class node:
def __init__(self, parent, daughters, edge):
self.parent = parent
self.daughters = daughters
self.edge = edge
trie.append(self)
self.index = len(trie) - 1
trie[parent].daughters.append(self.index)
...
def SuffixTreeConstruction():
global trie
print(len(trie))
for node in trie:
if len(node.daughters) == 1:
node.edge = ''.join([node.edge, trie[node.daughters[0]].edge])
...
我想取兩個不同節點的邊緣,並將它們組合爲一個字符串。邊緣是字符串的迭代(for base in text: create node with base as edge
),所以我假設它們是單個字符串,而不是字符(帶有數字值)。但是,它們顯然是整數。這有什麼明顯的原因嗎?爲什麼連接兩個字符串會產生類型錯誤?
Traceback (most recent call last):
File "trieMatching.1.py", line 149, in <module>
SuffixTreeConstruction()
File "trieMatching.1.py", line 106, in SuffixTreeConstruction
node.edge = ''.join([node.edge, trie[node.daughters[0]].edge])
TypeError: sequence item 1: expected str instance, int found
好像你有一個int,而不是一個字符串 – user3636636