diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2020-02-12 10:18:59 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-12 10:18:59 (GMT) |
commit | 8c579b1cc86053473eb052b76327279476740c9b (patch) | |
tree | bc99d5f52e1330500216512d1064c2f341b64d89 /Doc | |
parent | 0cc6b5e559b8303b18fdd56c2befd900fe7b5e35 (diff) | |
download | cpython-8c579b1cc86053473eb052b76327279476740c9b.zip cpython-8c579b1cc86053473eb052b76327279476740c9b.tar.gz cpython-8c579b1cc86053473eb052b76327279476740c9b.tar.bz2 |
bpo-32856: Optimize the assignment idiom in comprehensions. (GH-16814)
Now `for y in [expr]` in comprehensions is as fast as a simple
assignment `y = expr`.
Diffstat (limited to 'Doc')
-rw-r--r-- | Doc/whatsnew/3.9.rst | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/Doc/whatsnew/3.9.rst b/Doc/whatsnew/3.9.rst index c040410..ec17984 100644 --- a/Doc/whatsnew/3.9.rst +++ b/Doc/whatsnew/3.9.rst @@ -315,6 +315,17 @@ case), and one used ``__VENV_NAME__`` instead. Optimizations ============= +* Optimized the idiom for assignment a temporary variable in comprehensions. + Now ``for y in [expr]`` in comprehensions is as fast as a simple assignment + ``y = expr``. For example: + + sums = [s for s in [0] for x in data for s in [s + x]] + + Unlike to the ``:=`` operator this idiom does not leak a variable to the + outer scope. + + (Contributed by Serhiy Storchaka in :issue:`32856`.) + Build and C API Changes ======================= |