Skip to content

Instantly share code, notes, and snippets.

@skimbrel
Created October 22, 2013 22:49
Show Gist options
  • Save skimbrel/7109548 to your computer and use it in GitHub Desktop.
Save skimbrel/7109548 to your computer and use it in GitHub Desktop.
In [16]: def counter_factory():
....: count = [0]
....: def _counter():
....: count[0] += 1
....: return count[0]
....: return _counter
....:
In [17]: f = counter_factory()
In [18]: g = counter_factory()
In [19]: f()
Out[19]: 1
In [20]: g()
Out[20]: 1
In [21]: f()
Out[21]: 2
In [22]: f()
Out[22]: 3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment