[Python-ideas] filter-only list comps

Stephen J. Turnbull stephen at xemacs.org
Fri Feb 26 04:28:05 CET 2010


Greg Ewing writes:

 >    [x from stuff]
 > 
 > is a shorthand for
 > 
 >    [x for x in stuff]

Any time you say "shorthand" you're probably violating TOOWTDI. :-)

 > As a bonus, the short form could probably be made more
 > efficient, because the tuples produced by the for-loop
 > could be put straight into the result list, instead of
 > having to re-pack k and v into a new tuple.

This is a straightforward optimization that should be done anyway,
though, if it isn't done already.



More information about the Python-ideas mailing list