Last active
January 15, 2016 23:11
-
-
Save maphew/67c88807bf97bf67fbf9 to your computer and use it in GitHub Desktop.
response to http://stackoverflow.com/questions/2141098/list-comprehension-why-is-this-a-syntax-error
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Python 2.7.4 (default, Apr 6 2013, 19:54:46) [MSC v.1500 32 bit (Intel)] on win32 | |
Type "help", "copyright", "credits" or "license" for more information. | |
>>> | |
>>> my_list = 'one two tee'.split() | |
>>> | |
>>> my_list | |
['one', 'two', 'tee'] | |
>>> | |
>>> [print x for x in my_list] | |
File "<stdin>", line 1 | |
[print x for x in my_list] | |
^ | |
SyntaxError: invalid syntax | |
>>> | |
>>> [print(x) for x in my_list] | |
File "<stdin>", line 1 | |
[print(x) for x in my_list] | |
^ | |
SyntaxError: invalid syntax | |
>>> | |
>>> from __future__ import print_function | |
>>> | |
>>> [print(x) for x in my_list] | |
one | |
two | |
tee | |
[None, None, None] | |
>>> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
updated to include complete console output (previously was just the curious bits)