Skip to content

Instantly share code, notes, and snippets.

@horiajurcut
Created October 12, 2013 14:25
Show Gist options
  • Save horiajurcut/6950527 to your computer and use it in GitHub Desktop.
Save horiajurcut/6950527 to your computer and use it in GitHub Desktop.
from functools import wraps
from collections import defaultdict
def memo(func):
cache = {}
@wraps(func)
def wrap(*args):
if args not in cache:
cache[args] = func(*args)
return cache[args]
return wrap
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment