Skip to content

Instantly share code, notes, and snippets.

@yuttie
Last active October 17, 2016 06:38
Show Gist options
  • Select an option

  • Save yuttie/41d5616b7c7d52979cd4ecc256bac430 to your computer and use it in GitHub Desktop.

Select an option

Save yuttie/41d5616b7c7d52979cd4ecc256bac430 to your computer and use it in GitHub Desktop.
def make_counter(init):
count = [init]
def f():
count[0] += 1
return count[0] - 1
return f
c = make_counter(0)
c()
def make_counter(init):
count = init
def f():
nonlocal count
count += 1
return count - 1
return f
c = make_counter(0)
c()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment