class Node:
def __init__(self,dic_nodes = dict()):
self.dic_nodes = dic_nodes
root = Node()
print("original_root:", root)
word = "sci"
length = len(word)
for i in range(0, length):
if word[i] not in root.dic_nodes:
print("root:", root)
new_node = Node()
print("new_node:", new_node, len(new_node.dic_nodes))
root.dic_nodes[word[i]] = new_node
next = root.dic_nodes[word[i]]
print("next:", next, len(root.dic_nodes[word[i]].dic_nodes))
root = next
print("root:", root)
print()
Outputs are like this:
original_root: <__main__.Node object at 0x109eb1510>
root: <__main__.Node object at 0x109eb1510>
new_node: <__main__.Node object at 0x109ec3350> 0
next: <__main__.Node object at 0x109ec3350> 1
root: <__main__.Node object at 0x109ec3350>
root: <__main__.Node object at 0x109ec3350>
new_node: <__main__.Node object at 0x109eb1510> 1
next: <__main__.Node object at 0x109eb1510> 2
root: <__main__.Node object at 0x109eb1510>
root: <__main__.Node object at 0x109eb1510>
new_node: <__main__.Node object at 0x109ec3fd0> 2
next: <__main__.Node object at 0x109ec3fd0> 3
root: <__main__.Node object at 0x109ec3fd0>
My Problem:
The 2nd time I call Node() to construct a new object, I think "len(new_node.dic_nodes)" should also be 0 just like the 1st time I create a new object. I can't figure out where my problem is.