Created
March 17, 2015 11:53
-
-
Save sneeu/73e877adc7cfa3b437f7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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