... cache = {}
...
... def new_fn(n):
... if n in cache:
... print 'FOUND IN CACHE; RETURNING'
... return cache[n]
...
... # otherwise, call function & record value
... val = fn(n)
... cache[n] = val
... return val
...
... return new_fn
about all aspects of python programming and development
callable() function: