caesar0301 / treelib

An efficient implementation of tree data structure in python 2/3.
http://treelib.readthedocs.io/en/latest/
Other
800 stars 185 forks source link

how to replace a node with a new tree #194

Closed k3vinlusec closed 2 years ago

k3vinlusec commented 2 years ago

Hi,

treelib doesn't provide an API like replace(node, new) to implement replacing a node with a new tree. Does anyone know how to implement this functionality with the present API?

Thanks!

liamlundy commented 2 years ago

You should be able do this in two lines:

tree.remove_node(id_of_node_to_remove)
tree.paste(new_tree)

If that doesn't work, please comment with a full, but concise working example.

liamlundy commented 2 years ago

Gonna close this for now, but lmk if you have any more questions