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

Shane Green shane at umbrellacode.com
Tue Jun 25 16:16:29 CEST 2013


There was a length discussion on a related topic within the last couple of months.  I’ve attached the seed email for that discussion.  

A long discussion ensued but it may be easier to follow if you look it up in the archives as I don’t want to accidentally span the list by attaching the whole chain...







On Jun 25, 2013, at 7:05 AM, Amaury Forgeot d'Arc <amauryfa at gmail.com> wrote:

> Hi,
> 
> 2013/6/25 <jimjhb at aol.com>
> Syntax:
> 
> for X in ListY while conditionZ:
> 
> The 'for' loop would proceed as long as conditionZ remains true.
> 
> It seems that itertools.takewhile does the same thing:
> http://docs.python.org/2/library/itertools.html#itertools.takewhile
> It will probably require a lambd
>  
> 
> The motivation is to be able to make use of all the great aspects of the python 'for' (no indexing or explicit
> end condition check, etc.) and at the same time avoiding a 'break' from the 'for'.  
> 
> (NOTE:  Many people are being taught to avoid 'break' and 'continue' at all costs, so they instead convert
> the clean 'for' into a less-clean 'while'.  Or they just let the 'for' run out.  You can argue against this teaching
> practice (at least for Python) but that doesn't mean it's not prevalent and prevailing.)
> 
> Ouch! do you have pointers?
> Maybe we should upgrade these teaching practices (or teachers) instead.
> 
>  
> [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.]
> 
> I'm not super familiar with CPython, but I'm pretty sure I could get this up and working without too much effort.
> 
> Please note that I don't feel the answer to this is 'just use break'.  Programmers are now being taught to avoid 'break' and 'continue' as if they were 'goto's.  The result (now) is that people are avoiding the 'for' (with its GREAT properties) because they can't break out of it.
> 
> Comments and Questions welcome.
> 
> Thanks.  
> 
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> http://mail.python.org/mailman/listinfo/python-ideas
> 
> 
> 
> 
> -- 
> Amaury Forgeot d'Arc
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> http://mail.python.org/mailman/listinfo/python-ideas

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20130625/9cb9842e/attachment.html>
-------------- next part --------------
An embedded message was scrubbed...
From: "Wolfgang Maier" <wolfgang.maier at biologie.uni-freiburg.de>
Subject: [Python-ideas] while conditional in list comprehension ??
Date: Mon, 28 Jan 2013 14:33:45 +0100
Size: 6097
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20130625/9cb9842e/attachment.eml>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20130625/9cb9842e/attachment-0001.html>


More information about the Python-ideas mailing list