'while' in list comprehension?
Alex Martelli
aleax at aleax.it
Thu Nov 13 11:49:07 EST 2003
Greg Ewing (using news.cis.dfn.de) wrote:
> Hannu Kankaanp?? wrote:
>> Another variation:
>>
>> foo = [i for i in bar, break if len(i) == 0]
>>
>> This wouldn't need a new keyword.
>
> My thoughts on all this are that if you want to do
> something that procedural, it would be better written
> out as nested statements. List comprehensions are
> meant to be read declaratively.
Yes, they are. Still,
[ i for i in bar while len(i) ]
DOES read pretty declaratively to me (while the "break"
version admittedly doesn't).
Alex
More information about the Python-list
mailing list