'while' in list comprehension?

Andrae Muys amuys at shortech.com.au
Sat Oct 25 00:50:03 EDT 2003


Jeff Epler <jepler at unpythonic.net> wrote in message news:<mailman.34.1066855592.702.python-list at python.org>...
> Use 2.3's itertools:
>     foo = [i for i in itertools.takewhile(lambda i: len(i) > 0, bar)]
> or maybe
>     foo = list(itertools.takewhile(len, bar)]
> or even
>     foo = itertools.takewhile(len, bar) # an iterable, not a list
> 

or list(takewhile(len, bar))

from itertools import * :)

Andrae




More information about the Python-list mailing list