A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2011-May/111501.html below:

[Python-Dev] Don't set local variable in a list comprehension or generator

[Python-Dev] Don't set local variable in a list comprehension or generator [Python-Dev] Don't set local variable in a list comprehension or generatorNick Coghlan ncoghlan at gmail.com
Thu May 19 11:03:10 CEST 2011
On Thu, May 19, 2011 at 7:34 AM, Victor Stinner
<victor.stinner at haypocalc.com> wrote:
> But it is slower whereas I read somewhere than generators are faster
> than loops.

Are you sure it wasn't that generator expressions can be faster than
list comprehensions (if the memory savings are significant)?

Or that a reduction function with a generator expression can be faster
than a module-level explicit loop (due to the replacement of
dict-based variable assignment with fast locals in the generator and C
looping in the reduction function)?

In general, as long as both are using fast locals and looping in
Python, I would expect inline looping code to be faster than the
equivalent generator (but often harder to maintain due to lack of
reusability).

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4