The rap against "while True:" loops

Paul Rubin http
Wed Oct 14 00:47:07 CEST 2009

Steven D'Aprano <steven at> writes:
> But the consequence of that simplicity and speed is that they're not as 
> general as a for-loop. This was a design decision. But change the design 
> and you could have something like this:
> [expr for name in seq until cond]
> which breaks when cond becomes true.

from itertools import takewhile
xs = [expr(name) for name in takewhile(lambda s: not cond(s), seq)]

More information about the Python-list mailing list