Created
January 7, 2015 16:24
-
-
Save toshsan/acd06342e3a221a992e7 to your computer and use it in GitHub Desktop.
memoize
This file contains 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
def memoize(function): | |
cache = {} | |
def wrap(*args): | |
if not args in cache: | |
print '{0} not in {1}'.format(args, cache) | |
cache[args] = function(*args) | |
return cache[args] | |
return wrap | |
@memoize | |
def plus_one(n): | |
return n + 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment