[Python-ideas] Add "while" clauses to generator expressions

Boris Borcic bborcic at gmail.com
Sun Jan 11 13:05:18 CET 2009

Gerald Britton wrote:
> as well, like this:
> a = (i for i in range(100) while i <=50)

there was a longish thread on the subject back in august '08, where I pointed out

> you can do something like
>>>> def yet(b) :
>     if b : raise StopIteration
>>>> list(x for x in range(0,10) if not yet(x>4))
> [0, 1, 2, 3, 4]

but I was then answered that this "worked by accident" which apparently meant 
that 3.0 pedagogical doctrine wants [x for x...] to be strictly equivalent to 
list(x for x...), while this equivalence in fact doesn't extend to similar uses 
of StopIteration.

Cheers, BB

More information about the Python-ideas mailing list