Skip to content

Instantly share code, notes, and snippets.

@talwai
Created January 14, 2015 00:28
Show Gist options
  • Save talwai/68bdceccdd97c4c4916f to your computer and use it in GitHub Desktop.
Save talwai/68bdceccdd97c4c4916f to your computer and use it in GitHub Desktop.
Python 2.7 Leaking scope in list comprehensions
# This leaks in Python 2.7 but does not in Python 3+
def bad_scope_list():
num = range(1,10)
i = 4
print [i for i in num]
print i # Prints 9 instead of 4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment