[Python-Dev] Examples for PEP 572
Steven D'Aprano
steve at pearwood.info
Tue Jul 3 22:42:06 EDT 2018
More information about the Python-Dev mailing list
Tue Jul 3 22:42:06 EDT 2018
- Previous message (by thread): [Python-Dev] Examples for PEP 572
- Next message (by thread): [Python-Dev] Examples for PEP 572
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Tue, Jul 03, 2018 at 09:54:22PM -0400, Terry Reedy wrote: > > results = [(x, y, x/y) for x in input_data for y in [f(x)] if y > 0] > > Would (f(x),) be faster? There is a deferred feature request to optimize "for x in [item]" as equivalent to "for x in (item,)", to avoid constructing a list: https://bugs.python.org/issue32856 Since it only affects the internal byte-code, not visible semantics (aside from speed and memory) I think that's a neat micro-optimization regardless of whether it is applied to comprehensions or regular for-loops or both. -- Steve
- Previous message (by thread): [Python-Dev] Examples for PEP 572
- Next message (by thread): [Python-Dev] Examples for PEP 572
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-Dev mailing list