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

2006-08-06 Thread Eighty
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)) + Since Python favors list comprehensions over map, filter, and reduce, this would be the preferred way to do this + "Takewhile operations"

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

2006-08-06 Thread Eighty
Duncan Booth wrote: > 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 wou

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

2006-08-08 Thread Eighty
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)) > > + Since Python favors list comprehensions over map, filter, and reduce, > this

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

2006-08-08 Thread Eighty
Terry Reedy wrote: > whereas the analogous expansion of your proposal > > for x in xs: > while cond(x): > yield e(x) > > is an infinite loop and not at all what you mean. You're right. The syntax is ambiguous. I agree it's not a good idea, now. :) > x for x in xs while cond(x) if blah(x)