Skip to content

Instantly share code, notes, and snippets.

@BrettBukowski
Created July 27, 2014 23:17
Show Gist options
  • Save BrettBukowski/673ac8e2190a85daa2de to your computer and use it in GitHub Desktop.
Save BrettBukowski/673ac8e2190a85daa2de to your computer and use it in GitHub Desktop.
Python memoize decorator
import cPickle as pickle
def memoize(func):
results = {}
def wrapper(*args):
key = pickle.dumps(args)
if key not in results:
results[key] = func(*args)
return results[key]
return wrapper
@memoize
def some_repeatedly_called_func:
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment