Re: "For" loop and list comprehension similarity
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.python archive

Re: "For" loop and list comprehension similarity

From: Terry Reedy <tjreedy@udel.edu>
Date: Mon Mar 27 2006 - 06:10:31 CEST

<s.lipnevich@gmail.com> wrote in message
news:1143414870.330921.305890@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
Received on Sun Apr 30 21:16:57 2006