What is the fastest way to create a family tree out of a dict that looks like this:
family = [
{'name': 'a', 'parent': ''},
{'name': 'b', 'parent': 'a'},
{'name': 'c', 'parent': 'a'},
{'name': 'd', 'parent': 'b'},
{'name': 'e', 'parent': 'd'},
{'name': 'f', 'parent': ''},
{'name': 'g', 'parent': 'f'},
{'name': 'h', 'parent': 'a'}
]
Ultimately, I am trying to print it out (with a ton of extra info, but this is the general idea), a list like this:
a
b
d
e
c
h
f
g
Is the solution to create a function to loop over the list until it is empty, using .pop() on each item it finds the parent to? Or is there a better way in python?
This is a part of a much bigger problem, however, I am trying to find the best way to do this small little part. So even tho a nightmare of lambda's is probably possible. Please try to answer in a clean way which is easily extendable :)