A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2009-January/085200.html below:

Add a "while" clause to generator expressions

[Python-Dev] PEP 3142: Add a "while" clause to generator expressions [Python-Dev] PEP 3142: Add a "while" clause to generator expressionsTerry Reedy tjreedy at udel.edu
Tue Jan 20 00:52:07 CET 2009
Kristján Valur Jónsson wrote:
> Are you all certain that this mapping from a generator expression to
> a foor loop isn't just a happy coincidence?

Yes, The manual *defines* the meaning of a comprehension in terms of the 
corresponding nested statements.

"The comprehension consists of a single expression followed by at least 
one for clause and zero or more for or if clauses. In this case, the 
elements of the new container are those that would be produced by 
considering each of the for or if clauses a block, nesting from left to 
right, and evaluating the expression to produce an element each time the 
innermost block is reached." (3.0 doc)

It was originally defined as exactly equivalent (with empty list 
initialization added).  The only intended change of the slightly softer 
newer version is that the target name bindings do not escape the scope 
of the comprehension.

The proposed change would BREAK the definition and intent of what a 
comprehension means.

 > After all, the generator statement is just a generalization
 > of the list comprehension

I would call it a variation.  Syntactically, a generator statement is a 
comprehension with parentheses instead of square brackets or curly braces.

tjr

More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4