Find the similarity metric between two strings

前端 未结 11 1959
长情又很酷
长情又很酷 2020-11-22 13:24

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 standar

11条回答
  •  借酒劲吻你
    2020-11-22 14:16

    You can create a function like:

    def similar(w1, w2):
        w1 = w1 + ' ' * (len(w2) - len(w1))
        w2 = w2 + ' ' * (len(w1) - len(w2))
        return sum(1 if i == j else 0 for i, j in zip(w1, w2)) / float(len(w1))
    

提交回复
热议问题