I haven\'t found anything relevant on Google, so I\'m hoping to find some help here :)
I\'ve got a Python list as follows:
[[\'hoose\', 200], [\"Ba
import Levenshtein
data = [['hoose', 200],
["Bananphone", 10],
['House', 200],
["Bonerphone", 10],
['UniqueValue', 777]]
already_merged = []
for word, score in data:
added_to_existing = False
for merged in already_merged:
for potentially_similar in merged[0]:
if Levenshtein.distance(word, potentially_similar) < 5:
merged[0].add(word)
merged[1] += score
added_to_existing = True
break
if added_to_existing:
break
if not added_to_existing:
already_merged.append([set([word]),score])
print (already_merged)
@Mark thanks for such easy solution.