我试图在迭代时从集合中移除元素
matches = defaultdict(list)
for id_a in indices:
for id_b in indices:
if id_a != id_b:
if similar(id_a, id_b, threshold):
matches[id_a] += [id_a, id_b]
indices.difference_update({id_a, id_b})
def similar(a,b,threshold=0.7):
return True if difflib.SequenceMatcher(None, a, b).ratio() > threshold else False
indices={'aaabbb', 'aabbb', 'aabb', 'aaa', 'bbb'}
matches = {‘aaabbb’: [‘aabb’, ‘aabbb’]}
indices
是一个集合,similar
是一个函数,它检查id_a
和{defaultdict
matches
将添加{
但我有个错误:
^{pr2}$我想知道如何解决它,同时实现目标。在
目前没有回答
相关问题 更多 >
编程相关推荐