How to memoize functions?
Aahz
aahz at pythoncraft.com
Thu Jun 26 21:00:57 EDT 2003
In article <3efb54b3$1_2 at corp-news.newsgroups.com>,
Chris Reedy <creedy at mitretek.org> wrote:
>
>The obvious way to memoize a function would be to keep a dictionary with
>keys being tuples (or maybe dictionaries) of previous argument lists
>and values being the results of the previous computations.
Here's an idea: make the argument to your function a single class
instance. Use a simple LRU cache where you store a timestamp in your
dict along with the result. (The dict key is the class instance.)
--
Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/
Usenet is not a democracy. It is a weird cross between an anarchy and a
dictatorship.
More information about the Python-list
mailing list