def _process_node(node, aliases, duplicates):
 stack = _post_order(node)
 key = list()
 for item in stack:
  if ((type(item[0]) is str) and (item not in aliases)):
   key.append(item[0])
  else:
   key.append(item[0:2])
 key = tuple(key)
 dup_node = duplicates.get(key, False)
 if dup_node:
  node[0] = dup_node
  stack = None
 else:
  duplicates[key] = stack[(-1)]
  aliases.add(stack[(-1)])
 while (len(node) > 3):
  node.pop()
 return stack

def _process_node ( node , aliases , duplicates ) : stack = _post_order ( node ) key = list ( ) for item in stack : if ( ( type ( item [ 0 ] ) is str ) and ( item not in aliases ) ) : key . append ( item [ 0 ] ) else : key . append ( item [ 0 : 2 ] ) key = tuple ( key ) dup_node = duplicates . get ( key , False ) if dup_node : node [ 0 ] = dup_node stack = None else : duplicates [ key ] = stack [ ( - 1 ) ] aliases . add ( stack [ ( - 1 ) ] ) while ( len ( node ) > 3 ) : node . pop ( ) return stack
takes a node from the tree and searchs for any previously processed duplicates .