python 2.7 - Iterate through dictionary to compare value with all other values and output relevant keys -
i have dictionary this:
dictionary = {"harry":"some text","john":"smoe txet","paul":"other words",...} i want iterate through values of dictionary , compare each value other values in dictionary. if value unique, want output key of value. if 2 values being compared on 50% similar, want output corresponding key of 1st value.
i want end list:
results = ["harry","paul"] this because values of harry , john similar enough 1 of keys needs output results.
this have far:
from difflib import sequencematcher import itertools results = [] def similar(a, b): return sequencematcher(none, a, b).ratio() a,b in itertools.combinations(dict.itervalues(),2): if similar(a,b) > 0.5: #and key of value not in results #append key of value results if similar(a,b) < 0.5: #for other values #append key of value results what best way achieve this?
Comments
Post a Comment