-
-
Save falsetru/6577437 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
functions = [] | |
for val in ['foo', 'bar', 'baz']: | |
def f(val=val): | |
return val | |
functions.append(f) | |
for func in functions: | |
print(func()) |
This file contains hidden or 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
class Identity: | |
def __init__(self, val): | |
self.val = val | |
def __call__(self): | |
return self.val | |
functions = map(Identity, ['foo', 'bar', 'baz']) | |
for func in functions: | |
print(func()) |
This file contains hidden or 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
import functools | |
identity = lambda x: x | |
functions = [functools.partial(identity, x) for x in ['foo', 'bar', 'baz']] | |
for func in functions: | |
print(func()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment