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()
Я хочу, чтобы приведенный выше код выводил [1]
, однако он выводит [1, 2, 3, 4, 5]
.Почему это так, и как мне исправить это?