class Node:
children = {}
sequence = [1,2,3,4,5]
tree = Node()
node = tree
for item in sequence:
if item not in node.children:
node.children[item] = Node()
node = node.children[item]
print tree.children.keys()
I want the above code to output [1], however it outputs [1, 2, 3, 4, 5]. Why is this, and how would I go about fixing it?
Node.childrenis a class attribute. Make it an instance attribute instead.