def drop_duplicate_nodes(tree, inserted_nodes):
 for (name, node_list) in inserted_nodes.items():
  if (len(node_list) == 1):
   continue
  node_list.sort(key=(lambda x: x.Score), reverse=True)
  node_to_keep = node_list[0]
  for n in node_list:
   if (n is node_to_keep):
    continue
   elif (n.Parent is not None):
    n.Parent.remove(n)
 tree.prune()
 return tree

def drop_duplicate_nodes ( tree , inserted_nodes ) : for ( name , node_list ) in inserted_nodes . items ( ) : if ( len ( node_list ) == 1 ) : continue node_list . sort ( key = ( lambda x : x . Score ) , reverse = True ) node_to_keep = node_list [ 0 ] for n in node_list : if ( n is node_to_keep ) : continue elif ( n . Parent is not None ) : n . Parent . remove ( n ) tree . prune ( ) return tree
remove nodes from tree .