You aren't calling the Node
constructor that you created when you create any Node other than Node1
. You are instead creating 2-tuples, which have no val
attribute. Add a call to your Node constructor and everything should work fine:
# ...
Node8 = Node([], 8)
Node7 = Node([], 7)
Node6 = Node([], 6)
Node5 = Node([Node6], 5)
Node4 = Node([], 4)
Node3 = Node([Node7], 3)
Node2 = Node([Node4, Node5], 2)
Node1 = Node([Node2, Node3, Node8], 1)
# ...