def Memoize(func):
 @wraps(func)
 def wrapper(*args):
  if (args not in dg['cache']):
   dg['cache'][args] = func(*args)
  return dg['cache'][args]
 return wrapper

def Memoize ( func ) : @ wraps ( func ) def wrapper ( * args ) : if ( args not in dg [ 'cache' ] ) : dg [ 'cache' ] [ args ] = func ( * args ) return dg [ 'cache' ] [ args ] return wrapper
memoize decorator .