Skip to content

Instantly share code, notes, and snippets.

@toshsan
Created January 7, 2015 16:24
Show Gist options
  • Save toshsan/acd06342e3a221a992e7 to your computer and use it in GitHub Desktop.
Save toshsan/acd06342e3a221a992e7 to your computer and use it in GitHub Desktop.
memoize
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