def f(x): return x*x fmemo = {} def fm(x): if not x in fmemo: fmemo[x] = x*x return fmemo[x]