How to memoize functions?
aahz at pythoncraft.com
Fri Jun 27 03:00:57 CEST 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
More information about the Python-list