conditional computation
Bruno Desthuilliers
bdesth.quelquechose at free.quelquepart.fr
Thu Oct 26 18:47:50 EDT 2006
robert a écrit :
(snip)
> class MemoCache(dict): # cache expensive Objects during a session
> (memory only)
> def memo(self, k, f):
> try: return self[k]
> except IndexError:
> return self.setdefault(k, f())
> cache=MemoCache()
> ...
>
> o = cache.memo( complex-key-expr, lambda: expensive-calc-expr )
>
And how do you get back the cached value without rewriting both
complex-key-expr *and* expensive-calc-expr ? Or did I missed the point ?
More information about the Python-list
mailing list