Finding if two strings are almost similar

后端 未结 6 1390
小鲜肉
小鲜肉 2020-12-29 10:00

I want to find out if you strings are almost similar. For example, string like \'Mohan Mehta\' should match \'Mohan Mehte\' and vice versa. Another example, string like \'Um

6条回答
  •  暖寄归人
    2020-12-29 10:13

    You can use difflib.sequencematcher if you want something from the stdlib:

    from difflib import SequenceMatcher
    s_1 = 'Mohan Mehta'
    s_2 = 'Mohan Mehte'
    print(SequenceMatcher(a=s_1,b=s_2).ratio())
    0.909090909091
    

    fuzzywuzzy is one of numerous libs that you can install, it uses the difflib module with python-Levenshtein. You should also check out the wikipage on Approximate_string_matching

提交回复
热议问题