Skip to content

Instantly share code, notes, and snippets.

@winogradoff
Last active April 21, 2016 18:46
Show Gist options
  • Save winogradoff/cb47c5443570da850f1934e830ddb5fd to your computer and use it in GitHub Desktop.
Save winogradoff/cb47c5443570da850f1934e830ddb5fd to your computer and use it in GitHub Desktop.
Python memoize decorator
def memoize(obj):
cache = obj.cache = {}
@functools.wraps(obj)
def memoizer(*args, **kw):
if args not in cache:
cache[args] = obj(*args, **kw)
return cache[args]
return memoizer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment