Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
3 views
in Python by (47.6k points)

How do I get the probability of a string being similar to another string in Python?

I want to get a decimal value like 0.9 (meaning 90%) etc. Preferably with standard Python and library.

e.g.

similar("Apple","Appel") #would have a high prob. similar("Apple","Mango") #would have a lower prob.

1 Answer

0 votes
by (106k points)

To find the similarity metric between two strings you can use the below-mentioned code:-

from difflib import SequenceMatcher 

def similar(a, b): 

return SequenceMatcher(None, a, b).ratio()

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...