a potential pep to extend the syntax of for loops

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Mon Mar 9 11:35:17 EDT 2009


En Mon, 09 Mar 2009 07:15:30 -0200, pang <pablo.angulo at uam.es> escribió:

>   This is an idea about something I'd like to see implemented in
> python.

The python-ideas list exists to discuss this sort of things.

> The syntax of a for loop is restricted to the following:
>>>>    for element in list:
>>>>        instructions

Note that "list" in your description may be any expression list, in  
particular a conditional expression. This is currently valid:

for e in iterable1 if cond else iterable2:
   do something

In your proposal, depending whether there is an "else" clause or not, the  
"if" should be attached to the expression or the for statement. I'm unsure  
if this still can be represented as an LL(1) grammar (and Guido always  
said he wants the grammar to stay LL(1)).

-- 
Gabriel Genellina




More information about the Python-list mailing list