'while' in list comprehension?
Jeff Epler
jepler at unpythonic.net
Wed Oct 22 16:46:26 EDT 2003
More information about the Python-list mailing list
Wed Oct 22 16:46:26 EDT 2003
- Previous message (by thread): 'while' in list comprehension?
- Next message (by thread): 'while' in list comprehension?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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
Jeff
- Previous message (by thread): 'while' in list comprehension?
- Next message (by thread): 'while' in list comprehension?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list