Re: Memoization in Python

2007-01-05 Thread Alec Mihailovs
"Gabriel Genellina" <[EMAIL PROTECTED]> wrote > > Nice. There is already a memoize decorator in the Python wiki: > http://wiki.python.org/moin/PythonDecoratorLibrary, you can get some ideas > from there. Using the functools module (2.5) or the decorator module by M. > Simoniato (http://www.phyas

Re: Memoization in Python

2007-01-05 Thread Gabriel Genellina
At Friday 5/1/2007 06:50, Alec Mihailovs wrote: Following Antti Karttunen suggestion, I wrote the following simple decorator for creating functions with cache (something like 'option remember' in Maple). Just wanted to share it: Nice. There is already a memoize decorator in the Python wiki: h

Memoization in Python

2007-01-05 Thread Alec Mihailovs
Following Antti Karttunen suggestion, I wrote the following simple decorator for creating functions with cache (something like 'option remember' in Maple). Just wanted to share it: def function_with_cache(f): def new_f(*args): if args in new_f.cache: return new_f.cache[args]