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!
Written by Tristram Oaten
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Python
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#