Self reordering list in Python

Fredrik Lundh fredrik at
Fri Sep 16 18:38:58 CEST 2005

Terry Hancock wrote:

> This is actually the use-case for an "LRU cache"="least recently used
> cache", which is probably already implemented in Python somewhere (or
> even as a fast extension).  I'd do a google search for it.

reposted, in case there are more people who cannot be bothered
to read other replies before posting:

(it's a straight-forward and rather flexible implementation, which uses
a dictionary to quickly find existing objects, and a heap to keep track
of access times.  if you have more control over the stuff that goes into
the cache, you can strip things down to 10-20 lines of code and code
it in about the same time it took me to write this post)


More information about the Python-list mailing list