Proposal: [... for ... while cond(x)]

Duncan Booth duncan.booth at invalid.invalid
Sun Aug 6 12:31:33 EDT 2006


Eighty wrote:

> I suggest a new extension of the list comprehension syntax:
> 
> [x for x in xs while cond(x)]
> 
> which would be equivalent to
> 
> list(itertools.takewhile(cond, xs))
> 

What would this syntax offer that:

   [x for x in takewhile(cond, xs)]

doesn't currently offer? (Apart, that is, from saving you 3 characters of 
typing)



More information about the Python-list mailing list