[Python-ideas] while conditional in list comprehension ??

Carl Smith carl.input at gmail.com
Fri Feb 21 09:24:18 CET 2014


 

> I'm not sure if it is the goal to be able to break out of any level of 
> nesting or at least that's not how I interpreted the original 
> proposal. It is what happens for this stop() function but only because 
> there's no other way.


As I'm reading it, the while clause would be evaluated once for each 
iteration of the innermost loop, and would be able to access the current 
values of every loop.

*ls = [ line for file in files for line in file while file or line ]*

...would become...

ls = []
for file in files:
    for line in file:
        if not (file or line): break # break if not while_expression
*        ls.append(line)*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20140221/9099a854/attachment.html>


More information about the Python-ideas mailing list