Half-baked idea: list comprehensions with "while"

Kiuhnm kiuhnm03.4t.yahoo.it
Thu Apr 26 13:57:21 EDT 2012


On 4/26/2012 19:48, Paul Rubin wrote:
> Roy Smith<roy at panix.com>  writes:
>> x = [a for a in iterable while a]
>
> from itertools import takewhile
>
> x = takewhile(bool, a)

I see that as a 'temporary' solution, otherwise we wouldn't need 'if' 
inside of list comprehensions either.

Kiuhnm



More information about the Python-list mailing list