On 2022-09-19 17:31:31 +0000, Christman, Roger Graydon wrote: > And fortunately, Python makes memoization very easy, by using a > dictionary as a default value. I've done that often for classroom > purposes for cases where it makes a big difference (recursive > Fibonacci accelerates from exponential time to linear time). And the > process is straightforward enough that you could even define a > decorator that could be applied to any function you choose.
Such a decorator is already part of the Python standard library: https://docs.python.org/3/library/functools.html#functools.lru_cache hp -- _ | Peter J. Holzer | Story must make more sense than reality. |_|_) | | | | | h...@hjp.at | -- Charles Stross, "Creative writing __/ | http://www.hjp.at/ | challenge!"
signature.asc
Description: PGP signature
-- https://mail.python.org/mailman/listinfo/python-list