Created
November 20, 2012 22:45
-
-
Save dfm/4121783 to your computer and use it in GitHub Desktop.
y u suck so much?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fs = [] | |
for i in range(10): | |
fs.append(lambda: i) | |
print [f() for f in fs] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fs = [] | |
for i in range(10): | |
def f(j): | |
return lambda: j | |
fs.append(f(i)) | |
print [f() for f in fs] |
Iloveclosures
This stuff is always a pain. Your solution is nice, though.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What is the output....?