Skip to content

Instantly share code, notes, and snippets.

@falsetru
Forked from Hardtack/ex.py
Last active December 23, 2015 03:59
Show Gist options
  • Save falsetru/6577437 to your computer and use it in GitHub Desktop.
Save falsetru/6577437 to your computer and use it in GitHub Desktop.
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