memoization (original Subject lost because mailer lost the whole thread)
Peter J. Holzer
hjp-python at hjp.at
Tue Sep 20 03:11:24 EDT 2022
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.
|_|_) | |
| | | hjp at hjp.at | -- Charles Stross, "Creative writing
__/ | http://www.hjp.at/ | challenge!"
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://mail.python.org/pipermail/python-list/attachments/20220920/ca31bb75/attachment.sig>
More information about the Python-list
mailing list