Copying an AnyTree in Python

Question:

I want to take the node of a tree created with AnyTree and copy the whole tree so I can make changes to it without changing the original.

The only thing that I can think of is looping through the whole tree and copying the nodes one by one adding the new nodes as children to each other in the right order. But that seems awfully intricate, i.e. not very pythonic.

Is there an easy way of doing this?

Asked By: Lilly

||

Answers:

If AnyThree doesn’t have any function to duplicate then you may try to use standard module copy.deepcopy() (or you will have to copy nodes one by one).

Answered By: furas
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.