|
|
|
|
|
by sago
3727 days ago
|
|
Yes, that was a pain. Particularly because it was only true of list comprehensions, not dict comprehensions or generators: Python 2.7.10 ...
>>> a = 3
>>> [a for a in range(10)]
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> a
9
>>> a = 3
>>> list(a for a in range(10))
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> a
3
Guido called it Python's 'dirty little secret'. It is fixed in Py3 though. |
|