Devo scrivere una funzione che accetta una stringa come argomento e riconduce questa stringa a due altre stringhe e restituisce la stringa più simile e il numero di differenze.confronto di due stringhe e restituisce quello più simile
def func("LUMB"):
lst=["JIBM", "NUNE", "NUMB"]
should return:
("NUMB",1)
ho provato:
def f(word):
lst=["JIBM", "NUNE", "NUMB"]
for i in lst:
d=k(word, lst)
return differences
for n in d:
print min(sum(n))
dove:
def k(word1, word2):
L=[]
for w in range(len(word1)):
if word1[w] != word2[w]:
L.append(1)
else:
L.append(0)
return L
in modo che io ottenere un elenco di esempio, [1,0,0,0] se word1 = "NUMB "e word2 =" LUMB"
Hai visto [Algoritmo di differenza del testo] (http://stackoverflow.com/questions/145607/text-difference-algorithm) e [Good Python modules per il confronto stringa fuzzy] (http://stackoverflow.com/questions/682367/good-python-modules-for-fuzzy-string-comparison) – Chris
Un numero di risposte sarebbe disponibile anche su questo link http://stackoverflow.com/questions/682367/good-python-modules-for-fuzzy -stringa-confronto –
Sul sito c'è un post simile. Si otterrebbero alcune risposte più preziose qui http://stackoverflow.com/questions/682367/good-python-modules-for-fuzzy-string-comparison –