[Python-ideas] Is this PEP-able? for X in ListY while conditionZ:

Joshua Landau joshua.landau.ws at gmail.com
Tue Jun 25 20:17:19 CEST 2013


On 25 June 2013 18:12, Shane Green <shane at umbrellacode.com> wrote:
> [x for x in l if x < 10 else break]?

Humorously, this works:

def brk(): raise StopIteration
(x if x < 10 else brk() for x in range(100))
list(x if x < 10 else brk() for x in range(100))


Quirkily, but obvious with thought, this does not:

[x if x < 10 else brk() for x in range(100)]


More information about the Python-ideas mailing list