Skip to content

Instantly share code, notes, and snippets.

@Sushant
Created November 25, 2014 02:41
Show Gist options
  • Select an option

  • Save Sushant/89ce5231602a7d5ebd06 to your computer and use it in GitHub Desktop.

Select an option

Save Sushant/89ce5231602a7d5ebd06 to your computer and use it in GitHub Desktop.
Memoizing in Python
from functools import wraps
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