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