"For" loop and list comprehension similarity

Terry Reedy tjreedy at udel.edu
Mon Mar 27 06:10:31 CEST 2006


<s.lipnevich at gmail.com> wrote in message 
news:1143414870.330921.305890 at j33g2000cwa.googlegroups.com...
>> Why not combine the two:
>
> I guess because (at least in source code) you're doing a loop twice
> :-). I don't know what a compiler would do. I think though that the
> "for i in c if test:" construct is more readable and maybe can even be
> better optimized.

 There are also the filter and ifilter functions:

for i in filter(testfunc, c):

tjr






More information about the Python-list mailing list