I read the manual from https://anytree.readthedocs.io/en/latest/#, but I didn't figure out how to translate a dictionary to tree view, anyone can help?
data = {
'Marc': 'Udo',
'Lian': 'Marc',
'Dan': 'Udo',
'Jet': 'Dan',
'Jan': 'Dan',
'Joe': 'Dan',
}
output is
Udo
├── Marc
│ └── Lian
└── Dan
├── Jet
├── Jan
└── Joe
First you need to create the tree from your dict of "relationship" data, there are many ways to do this but here's an example:
Now you need to identify the root node, in your case it is the unique node which has no parent (Udo).
Once you have the root node, you can render the tree like this:
The
anytree
API is richer thanrich
, so it's a little more complicated withrich.tree
: