Created
December 3, 2012 22:20
-
-
Save haleyrc/4198663 to your computer and use it in GitHub Desktop.
Basic Memoization Class
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
| class Memoize: | |
| def __init__(self, func): | |
| self.prevs = {} | |
| self.func = func | |
| def __call__(self, *args): | |
| if not args in self.prevs: | |
| self.prevs[args] = self.func(*args) | |
| return self.prevs[args] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment