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

jimjhb at aol.com jimjhb at aol.com
Tue Jun 25 16:46:06 CEST 2013



You shouldn't have to invoke takewhile and a lambda just to break out of for loop.


>http://docs.python.org/2/library/itertools.html#itertools.takewhile
>
>for item in takewhile(lambda x: x < 5, range(10)):
>    pass

>>
>> [People who avoid the 'break' by functionalizing an inner portion of the
>> loop are just kidding themselves and making their own code worse, IMO.
>> Takewhile from itertools also works, but that's clumsy and wordy as well.]
>>


 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20130625/826dafd5/attachment.html>


More information about the Python-ideas mailing list