1from difflib import SequenceMatcher
2
3def similar(a, b):
4 return SequenceMatcher(None, a, b).ratio()
5
6>>> similar("Apple","Appel")
70.8
8>>> similar("Apple","Mango")
90.0
1def similar(w1, w2):
2 w1 = w1 + ' ' * (len(w2) - len(w1))
3 w2 = w2 + ' ' * (len(w1) - len(w2))
4 return sum(1 if i == j else 0 for i, j in zip(w1, w2)) / float(len(w1))
5