[Python-ideas] filter-only list comps

Greg Ewing greg.ewing at canterbury.ac.nz
Fri Feb 26 23:03:27 CET 2010


Stephen J. Turnbull wrote:
> Greg Ewing writes:
> 
>  > 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.

I don't think it's as straightforward as all that. You
can't do it at compile time, because even if the target
and result expression are textually identical, the
repacked item isn't necessarily the same type as the
one produced by the iteration.

-- 
Greg



More information about the Python-ideas mailing list