2 ms·
functools.lru_cache[1] from the standard library is a decorator that memoizes[2] a function. https://github.com/osteele/callgraph/blob/master/examples/callgrap
by osteele 9y ago
functools.lru_cache[1] from the standard library is a decorator that memoizes[2] a function.
https://github.com/osteele/callgraph/blob/master/examples/callgraph-decorator-examples.ipynb https://github.com/osteele/callgraph/blob/master/examples/ca... has some examples of using @lru_cache, together with a decorator (@callgraph) defined in that repo, that helps visualize recursion and memoization.
[1]: https://docs.python.org/3/library/functools.html#functools.lru_cache https://docs.python.org/3/library/functools.html#functools.l...
[2]: https://en.wikipedia.org/wiki/Memoization https://en.wikipedia.org/wiki/Memoization