Skip to content

Instantly share code, notes, and snippets.

@sneeu
Created March 17, 2015 11:53
Show Gist options
  • Save sneeu/73e877adc7cfa3b437f7 to your computer and use it in GitHub Desktop.
Save sneeu/73e877adc7cfa3b437f7 to your computer and use it in GitHub Desktop.
import functools
def memoize(f):
memos = {}
@functools.wraps(f)
def g(*args):
if args not in memos:
print 'Calling'
memos[args] = f(*args)
else:
print 'Not calling'
return memos[args]
return g
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment