Skip to content

Instantly share code, notes, and snippets.

@marksteve
Last active December 21, 2015 01:29
Show Gist options
  • Select an option

  • Save marksteve/6228150 to your computer and use it in GitHub Desktop.

Select an option

Save marksteve/6228150 to your computer and use it in GitHub Desktop.
def incrementer(i=1):
_l = dict()
def c(n=None):
if n:
_l.setdefault(n, 0)
_l[n] += i
return _l[n]
else:
return _l
return c
# In [2]: score = incrementer(10)
# In [3]: score('Steve')
# Out[3]: 10
# In [4]: score('Aaron')
# Out[4]: 10
# In [5]: score('Steve')
# Out[5]: 20
# In [6]: score()
# Out[6]: {'Aaron': 10, 'Steve': 20}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment