class memodict(dict):

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

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

def __missing__(self, key):
    ret = self[key] = self.f(*key)
return ret
Python list comprehension - want to avoid repeated evaluation