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

jimjhb at aol.com jimjhb at aol.com
Tue Jun 25 23:25:15 CEST 2013


Ned,


I'm sorry. I totally agree.  What I meant was that takewhile is the best alternative if you don't use break.
MISRA-C 2004 allows one break in a loop, so even MISRA is on board.  But their 1998 edict polluted a lot of minds....


-Jim



-----Original Message-----
From: Ned Batchelder <ned at nedbatchelder.com>
To: python-ideas <python-ideas at python.org>
Sent: Tue, Jun 25, 2013 5:17 pm
Subject: Re: [Python-ideas] Is this PEP-able? for X in ListY while	conditionZ:


          
    
    
On 6/25/2013 4:58 PM, jimjhb at aol.com      wrote:
    
    
I saw your        thread.  Thank you for summarizing the result!  It looks like        the best alternative is itertools.takewhile, but I don't like        it....  :(
        
      
    
    Ugh! The best alternative is "break."  The people              advocating not using break are doing so for "readability"              reasons.  I would be very surprised if they thought takewhile was more readable than                  a break statement.  Slavishly following mindless                        rules is not the way to write                          good programs, and it isn't the way to teach                          people to write good programs.
                          
                          Resist!  :)
                            
                            --Ned.
                              
                                
        -Jim
        
        
-----Original          Message-----
          From: Wolfgang Maier          <wolfgang.maier at biologie.uni-freiburg.de>
          To: python-ideas <python-ideas at python.org>
          Sent: Tue, Jun 25, 2013 4:51 pm
          Subject: Re: [Python-ideas] Is this PEP-able? for X in ListY          while conditionZ:
          
          
            
Hi,
I suggested the very same 'while in a comprehension/generator expression'
back in January:
http://mail.python.org/pipermail/python-ideas/2013-January/018969.html

There were many very useful responses suggesting alternative syntax (that
I'm using now).
The proposal itself was dismissed with the logic that comprehensions can
currently be translated directly into explicit for loops, e.g.:

[x for x in items if x!=0]

equals:

result=[]
for x in items:
    if x!=0:
        result.append(x)

This equivalence is considered *very* important and the while statement
would break it:

[x for x in items while x>0]

does *not* translate into:

for x in item:
    while x>0:
        result.append(x)

So, as long as you can't come up with syntax that translates properly,
there's no chance of getting it accepted.

Best,
Wolfgang


_______________________________________________
Python-ideas mailing list
Python-ideas at python.org
http://mail.python.org/mailman/listinfo/python-ideas

          
                  
            
      
      
      
_______________________________________________
Python-ideas mailing list
Python-ideas at python.org
http://mail.python.org/mailman/listinfo/python-ideas

    
    
  

_______________________________________________
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/a32fd360/attachment-0001.html>


More information about the Python-ideas mailing list