Implementation of the algorithm in Wiki article has a drawback. If the tree consists from only one root then nothing happen. The tree is not modified. How to fix this issue? In C++ it is possible to set root pointer to null, but what to do in python?
1 Answer
This is a continuation of a previous question, and the OP is looking to replace the value with None, but for all names that have that instance assigned to them - this is not possible in Python.
The answer is there is no way to delete the value in this case due to the way Python is designed - you would have to implement an object manager of some kind, store it in a container and access it through that, or change your design not to rely on mutation.
Another question worth asking - is this a case that is likely to happen? It may be possible (and desirable) just to define this as a limitation where the root node can't be destroyed. I can't think of a case where you would want that functionality.
Noneif you are trying to perform something similar tonullin c++None, but for all names that have that instance assigned to them - this is not possible in Python.