Proposed new syntax
Marko Rauhamaa
marko at pacujo.net
Thu Aug 17 01:54:58 EDT 2017
Ben Finney <ben+python at benfinney.id.au>:
> The Python list comprehension syntax does not specify control flow.
I understand your point, but how do you know your statement is true?
I didn't check this, but I would imagine the list comprehension:
[ f(x) for x in I if c(x) ]
was defined as syntactic sugar for:
list(f(x) for x in I if c(x))
where
f(x) for x in I if c(x)
has heavily iterative semantics.
> List comprehensions, in their syntax, strongly connote a single
> declarative operation. This makes them different from iteration
> syntax.
Except for side effects, you get the same result whichever way you
imagine it.
As a side not, I have found it rather confusing that I have to say:
[ (x, y) for x in range(5) for y in range(x) ]
instead of:
[ (x, y) for y in range(x) for x in range(5) ]
After all, you must say:
[ ((x, y) for y in range(x)) for x in range(5) ]
which, admittedly, means a different thing.
Marko
More information about the Python-list
mailing list