List comprehension

Jason Friedman jsf80238 at gmail.com
Fri Dec 30 14:37:46 EST 2016


$ python
Python 3.6.0 (default, Dec 26 2016, 18:23:08)
[GCC 4.8.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> data = (
... (1,2),
... (3,4),
... )
>>> [a for a in data]
[(1, 2), (3, 4)]

Now, this puzzles me:

>>> [x,y for a in data]
  File "<stdin>", line 1
    [x,y for a in data]
           ^
SyntaxError: invalid syntax

I expected:
[(1, 2), (3, 4)]



More information about the Python-list mailing list