Skip to content

Instantly share code, notes, and snippets.

@falsetru
Forked from Hardtack/ex.py
Last active Dec 23, 2015
Embed
What would you like to do?
functions = []
for val in ['foo', 'bar', 'baz']:
def f(val=val):
return val
functions.append(f)
for func in functions:
print(func())
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())
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