How to memoize functions?

Aahz aahz at
Fri Jun 27 03:00:57 CEST 2003

In article <3efb54b3$1_2 at>,
Chris Reedy  <creedy at> 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           <*>

Usenet is not a democracy.  It is a weird cross between an anarchy and a

More information about the Python-list mailing list