Skip to content

Instantly share code, notes, and snippets.

@ehermes
Created February 12, 2016 21:05
Show Gist options
  • Select an option

  • Save ehermes/c6b86b4ef9b6c5ff2ee4 to your computer and use it in GitHub Desktop.

Select an option

Save ehermes/c6b86b4ef9b6c5ff2ee4 to your computer and use it in GitHub Desktop.
def make_incrementors(start, amounts):
y = [start]
results = []
for x in amounts:
def add_x():
y[0] += x
return y[0]
results.append(add_x)
return results
incrementors = make_incrementors(7, [1, 2, 3, 4, 5])
print(incrementors)
print(incrementors[0]())
print(incrementors[1]())
print(incrementors[2]())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment