from difflib import SequenceMatcher def similar(a, b): return SequenceMatcher(None, a, b).ratio() Using it: >>> similar("Apple","Appel") 0.8 >>> similar("Apple","Mango") 0.0
Here is what the above code is Doing:
1. The SequenceMatcher class is initialized with the two strings.
2. The ratio method returns a float between 0 and 1, which tells us the similarity between the two strings.
3. The closer the value is to 1, the more similar the two strings are.