Skip to content

Instantly share code, notes, and snippets.

@dbrattli
Last active May 12, 2016 05:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dbrattli/a30d6c47c00c01a1b3943dd314bb85da to your computer and use it in GitHub Desktop.
Save dbrattli/a30d6c47c00c01a1b3943dd314bb85da to your computer and use it in GitHub Desktop.
Closing over loop variable considered harmful
actions=[]
for x in range(10):
actions.append(lambda: print(x))
for act in actions:
act()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment