The rap against "while True:" loops

Paul Rubin http
Tue Oct 13 18:47:07 EDT 2009


Steven D'Aprano <steven at REMOVE.THIS.cybersource.com.au> 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