Skip to content

Instantly share code, notes, and snippets.

@whiledoing
Created December 28, 2019 11:09
Show Gist options
  • Save whiledoing/a4081723a819a37525fd6824c9065faa to your computer and use it in GitHub Desktop.
Save whiledoing/a4081723a819a37525fd6824c9065faa to your computer and use it in GitHub Desktop.
[python-memo-decorator] python memo func call result decorator #python #util
from functools import wraps
def memoize(function):
memo = {}
@wraps(function)
def wrapper(*args):
try:
return memo[args]
except KeyError:
rv = function(*args)
memo[args] = rv
return rv
return wrapper
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment