Created
December 28, 2019 11:09
-
-
Save whiledoing/a4081723a819a37525fd6824c9065faa to your computer and use it in GitHub Desktop.
[python-memo-decorator] python memo func call result decorator #python #util
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
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