Proposed new syntax
Steven D'Aprano
steve+comp.lang.python at pearwood.info
Mon Aug 14 04:52:41 EDT 2017
On Sun, 13 Aug 2017 21:06:08 -0700, Rustom Mody wrote:
> Here's a bunch of different ways in which a mapping comprehension could
> be implemented:
Not in Python they couldn't be, since Python promises deterministic,
first-to-last evaluation in the same order as the equivalent for-loop.
When a list comprehension is supplied, it 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 list 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 a list element each time the innermost block is reached.
https://docs.python.org/2/reference/expressions.html#list-displays
The docs for Python 3 are equivalent:
https://docs.python.org/3/reference/expressions.html#displays-for-lists-
sets-and-dictionaries
See also the tutorial, which says more or less the same thing:
https://docs.python.org/2/tutorial/datastructures.html#list-comprehensions
--
“You are deluded if you think software engineers who can't write
operating systems or applications without security holes, can write
virtualization layers without security holes.” —Theo de Raadt
More information about the Python-list
mailing list