Skip to content

Instantly share code, notes, and snippets.

@joseanpg
Created November 15, 2010 20:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joseanpg/700913 to your computer and use it in GitHub Desktop.
Save joseanpg/700913 to your computer and use it in GitHub Desktop.
Sharing
def f(x):
def g(y):
def h1(z):
nonlocal x,y
x = z
y = 2*z
print(locals())
def h2(z):
print(locals())
return z+y+x
return [h1,h2]
return g
# >>> par = f(5)(10)
# >>> par[1](2)
# {'y': 10, 'x': 5, 'z': 2}
# 17
# >>> par[0](7)
# {'y': 14, 'x': 7, 'z': 7}
# >>> par[1](8)
# {'y': 14, 'x': 7, 'z': 8}
# 29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment