Skip to content

Instantly share code, notes, and snippets.

@zenloner
Created April 10, 2013 03:23
Show Gist options
  • Save zenloner/5351512 to your computer and use it in GitHub Desktop.
Save zenloner/5351512 to your computer and use it in GitHub Desktop.
using lambda to implement factory function
def makeActions():
acts = []
for i in range(5):
acts.append(lambda x : i ** x) # all remember same last i
return acts
acts = makeActions()
acts[0](2) # print 16
acts[2](2) # print 16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment