I have a basic class containing two attributes 'Name' and 'Children.
def __init__(self, name):
self.name = name
self.children = 
# Create Master Root Node
root = Node('root')
path = ['Leslie','Marie','Tori'] # simple example
path = ['Leslie','Marie','Tori','Kevin'] # more complex requires two nodes to be created
I'd do something like this. It's a non recursive solution.
def get_node_by_path(path): cur_node = root for elem_name in path: found = False for child in cur_node.children: if child.name == elem_name: cur_node = child found = True break if not found: new_node = Node(elem_name) cur_node.children.append(new_node) cur_node = new_node return cur_node