I have read this answer regarding the issue with using self
in a defaultis parameter in a Python method, but can't seem to make it work with my use case, which is a recursive call for tree traversal as shown below:
def in_order_traversal(self, node):
if node != None:
print(node, end=" ")
self.in_order_traversal(node.left)
self.in_order_traversal(node.right)
I have to call this with tree.in_order_traversal(tree.root)
but would rather just use tree.in_order_traversal()
, and have node=self.root
as the second argument inf the method definition.
Can someone please suggest how to use the "workaround" given in the answer linked to?