# Your previous Plain Text content is preserved below:
# 
# ValueError ValueError                ValueError
#     |          |                     |       |
#    foo        foo       ->          foo     zoo
#     |          |                    / \      |
#    bar        baz                 bar  baz  far
#    
# 
# ValueError
#     |
#    zoo
#     |
#    var
#    
# Given the list of exception traces. Merge them into a tree given a prefix merge criterion 
# illustrated above. 
# 
# Input -> k lists of exception traces 
# OUtput -> Tree
# 
# // ["ValueError", "foo", "bar"]
# // if tree's values doesn't contain exception or if node is null:
# // create node[String]
# // recurse pass children
# Tree merge (List<List<String>> ets)
# 
# 

# TODO:
# Change list_of_nodes into dictionary
Class ExceptionNode(object):
    def __init__(self, trace_name, list_of_nodes = {}):
        """
        :type:
        :type: 
        """
        self.trace_name = trace_name
        self.list_of_nodes = list_of_nodes
        
    def addTrace(self, node):
        self.list_of_nodes.append(node)
    
    def getTraceName(self):
        pass
    
    def getNodes(self):
        return self.list_of_nodes
    
    def findNode(self, test_trace):
        for t in list_of_nodes:
            if t.getTraceName() == test_trace:
                return t
        return None
    
trace1 = []
trace2 = []
    
def merge(list_of_exceptions):
    
    # ValueError as first
    stack_tree = ExceptionNode(list_of_exceptions[0][0])
    root = stack_tree
    
    # Depth-first approach
    
    for trace in list_of_exceptions:
        for exp in trace[1:]:
            if exp is not in stack_tree.getNodes():
                new_exp_tree = ExceptionNode(exp)
                stack_tree.addTrace(new_exp_tree)
                stack_tree = new_exp_tree
            else:
                stack_tree = stack_tree.findNode(exp)
        stack_tree = root        
    return root