Skip to content

Instantly share code, notes, and snippets.

@sonkm3
Created July 28, 2012 02:59
Show Gist options
  • Select an option

  • Save sonkm3/3191527 to your computer and use it in GitHub Desktop.

Select an option

Save sonkm3/3191527 to your computer and use it in GitHub Desktop.
python generator by closure (count passed via list)
def get_counter():
print 'get_counter'
def counter():
count[0] = count[0] + 1
return count[0]
count = [0]
return counter
counter = get_counter()
for lp in range(5):
print counter()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment