“TypeError: ‘NoneType’ object is not subscriptable,”
I’m presently working on a project that requires me to write a Binary Search Tree in Python. Everything worked OK until I received an error code that I can’t figure out. The problem code is “TypeError: ‘NoneType’ object is not subscriptable,” and it is thrown by a function I built to traverse the tree in order.
According to what I can see, the issue occurs on the line self.in order traversal (node.left). I’ve tried a few various solutions to the problem, including adding some print statements to examine what’s going on, but nothing seems to work.
One thing I discovered is that the issue only happens when I attempt to traverse a tree with a single node, as shown in this example (https://www.scaler.com/topics/data-structures/doubly-linked-list/). Everything works perfectly if I construct a tree with several nodes. Nevertheless, because the ability to handle a single node tree is critical for my project, I can’t simply ignore this issue.
I’m not sure what’s creating the problem or how to resolve it. I’ve tried for hours to figure it out, but I’m still stumped. Any assistance would be much appreciated!