I am very confused. Please help me to resolve this [closed]

Because the two objects are distinct instances. By default, python compare the memory adresses of objects.

To make it work, you need to implement a __eq__() methods in TreeNode to redefine how to compare this objects.

Leave a Comment