Created
December 6, 2016 12:37
-
-
Save danslapman/64ebc6d47a00cb0389354057e69c85f7 to your computer and use it in GitHub Desktop.
Python memoization decorator
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
__author__ = 'Daniil <danslapman> Smirnov' | |
__copyright__ = 'Copyleft 2013, danslapman' | |
__contact__ = 'https://bitbucket.org/danslapman/memoize' | |
def memoize(cache): | |
def memoize(fun): | |
def memoizator(*args, **kwargs): | |
if args in cache: | |
return cache[args] | |
else: | |
res = fun(*args, **kwargs) | |
cache[args] = res | |
return res | |
return memoizator | |
return memoize |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment