def memoize(f):
    'Memoization decorator for functions taking one or more arguments.'

    class Memo(dict):

        def __init__(self, f):
            super(Memo, self).__init__()
            self.f = f

        def __call__(self, *args):
            return self[args]

        def __missing__(self, key):
            ret = self[key] = self.f(*key)
            return ret
    return Memo(f)
Memoization decorator for functions taking one or more arguments.
def memoize(f):
    

    class Memo(dict):

        def __init__(self, f):
            super(Memo, self).__init__()
            self.f = f

        def __call__(self, *args):
            return self[args]

        def __missing__(self, key):
            ret = self[key] = self.f(*key)
            return ret
    return Memo(f)