def _keep_alive(x, memo):
 try:
  memo[id(memo)].append(x)
 except KeyError:
  memo[id(memo)] = [x]

def _keep_alive ( x , memo ) : try : memo [ id ( memo ) ] . append ( x ) except KeyError : memo [ id ( memo ) ] = [ x ]
keeps a reference to the object x in the memo .