Using anytree
I produced such tree:
A
├── B
│ └── C
│ └── D
│ └── F
└── B
└── C
└── E
└── G
Is there a way to remove all duplicate children and turn it into the tree below (recursive for children at all possible levels)?
A
└── B
└── C
├── D
| └── F
└── E
└── G
Edit:
What I am trying to achieve is a tree of all links on a website. So everything between slashes would become a child: .../child/...
(second slash is optional). The above is just a representation of my problem, but I hope it's clear.
Here is my Node generation:
root = Node('A')
for link in links:
children = link.split('/')
cur_root = Node(children[0], parent=root)
for one in children[1:]:
cur_root = Node(one, parent=cur_root)