Created
January 30, 2014 04:16
-
-
Save ayust/8702557 to your computer and use it in GitHub Desktop.
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
>>> def echo(s): | |
... print s | |
... | |
>>> funcs = [] | |
>>> for i in range(3): | |
... funcs.append(lambda: echo(i)) | |
... | |
>>> for func in funcs: | |
... func() | |
... | |
2 | |
2 | |
2 | |
>>> funcs = [] | |
>>> for i in range(3): | |
... funcs.append(partial(echo, i)) | |
... | |
>>> for func in funcs: | |
... func() | |
... | |
0 | |
1 | |
2 |
mathieucaroff
commented
Nov 9, 2018
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment