[Python-ideas] Filtered "for" loop with list-comprehension-like syntax

Terry Reedy tjreedy at udel.edu
Sun May 22 01:01:36 CEST 2011


On 5/20/2011 8:57 PM, Dan Baker wrote:

> It seems odd that "for x in y if z" is allowed in comprehensions but
> not in a regular for loop.

Comprehensions are expressions and therefore need everything packed into 
them that is needed.

For statements and if statement are statements and both can be followed 
in there suite with an many statements as needed, so there is no *need* 
to pack more than is necessary into the header line. Even doc strings, 
which are conceptually part of the header, were put down into the suite.

-- 
Terry Jan Reedy




More information about the Python-ideas mailing list