へっぽこびんぼう野郎のnewbie日記

けろけーろ(´・ω・`)! #vZkt8fc6J

One of the differences between Python2.x and Python3.x related to the Generator

2.x


$ python
Python 2.7.9 (default, Jan 29 2015, 06:28:58)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.56)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> x = 'hoge'
>>> a = [x for x in 1, 2]
>>> x
2
>>> exit()

3.x


$ python3
Python 3.4.2 (default, Jan 29 2015, 06:35:40)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.56)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> x = 'hoge'
>>> a = [x for x in 1, 2]
File "", line 1
a = [x for x in 1, 2]
^
SyntaxError: invalid syntax
>>> a = [x for x in [1, 2]]
>>> x
'hoge'
>>>