'while' in list comprehension?
Bob Gailer
bgailer at alum.rpi.edu
Wed Oct 22 16:41:58 EDT 2003
At 01:05 PM 10/22/2003, Emile van Sebille wrote:
>jsaul asks...
> > would then turn into
> >
> > foo = [ i for i in bar while len(i)>0 ]
> >
> > Is there any reason for not having this kind of thing? I actually
> > miss it pretty often.
> >
>
>
>How is this different from:
>
> foo = [ i for i in bar if len(i) ]
My reading is that the comprehension would stop at the first i whose len
were 0. e.g.
foo = []
for i in bar:
if len(i) == 0:break
foo.append(i)
Bob Gailer
bgailer at alum.rpi.edu
303 442 2625
-------------- next part --------------
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.525 / Virus Database: 322 - Release Date: 10/9/2003
More information about the Python-list
mailing list