merits of Lisp vs Python

Steven D'Aprano steve at REMOVE.THIS.cybersource.com.au
Sat Dec 9 23:08:25 EST 2006


On Sun, 10 Dec 2006 01:53:50 +0100, André Thieme wrote:

> You could maybe give another example: how would one realize something
> like (memoize function) in Python?

By spending thirty seconds googling:

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/325205
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/498110

If your needs are very simple, something as simple as this will do it:

def memoize(func):
    def f(arg, _cache={}):
        if _cache.has_key(arg):
            return _cache[arg]
        t = func(arg)
        _cache[arg] = t
        return t
    return f


> Or (defmethod name :after ..)?

I don't even know what that means. Would you like to translate?



-- 
Steven.




More information about the Python-list mailing list