repl.it
@anonymous/

StraightFixedPostgres

Python

No description

fork
loading
Files
  • main.py
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
children_and_parents = {
    "Mary": ["Patricia", "Lisa"], 
    "Patricia": ["Barbara", "Helen", "Maria"], 
    "Maria": ["Keren", "Carol"], 
    "Barbara": ["Betty"]
}

def draw_family_tree(tree, root, level=0, gap=3):
    if root:
        print(" " * level + root)

        if root in tree:
            for child in tree[root]:
                draw_family_tree(tree, child, level + gap)
        
def find_root(tree):
    children = set([x for y in tree.values() for x in y])
    
    for k in tree.keys():
        if k not in children:
            return k


draw_family_tree(children_and_parents, find_root(children_and_parents))