Open stevenlis opened 5 years ago
@StevenLi-DS I thinks it is not hard to do that if you are not concerned about the children order of each non-leaf nodes. You can implement this algorithms easily by traversing the returned list from paths_to_leaves
.
@StevenLi-DS can simply do... something like:
paths =tree.paths_to_leaves()
# [['a','b', 'c'], ['a', 'b', 'd'], ['a', 'b', 'e']]
[l.reverse() for l in paths]
# paths now equals [['c', 'b', 'a'], ['d', 'b', 'a'], ['e', 'b', 'e']]
This will reverse the contents of each of the lists returned.
The function of
paths_to_leaves
returns the following listBut what if I have such a list and want to construct a tree. If there a reversed
paths_to_leaves
function?If not, is there a workaround?