特里结构的工作原理

时间:2019-07-16 06:13:57

标签: python trie

我不明白current = trie(第2行)的行为。 它是如何分配和附加新值的?

trie = {}
current = trie
word = "hello"
for ch in word:

    if ch not in current:
        current[ch] = {}

    current = current[ch]

current['*'] = True

print(trie)
print (current)

给出输出:

{'h': {'e': {'l': {'l': {'o': {'*': True}}}}}}

{'*': True}

但是我期望trie的值不会改变。

b = 6 
a = b
a += 1 
print (a, b)

给出7 6.为什么b仍然指向6?

0 个答案:

没有答案
相关问题