Last Updated: February 25, 2016
·
377
· oatman

Dirty list comprehensions in python

>>> list = [1,2,3,4]
>>> [item for item in list]
[1, 2, 3, 4]
>>> item
4  # <-WTF?

So list comprehensions dirty up the scope by defining variables :-( This makes me very sad. But the good news is that it's been fixed in python 3!

Remember, minimise side effects wherever possible!