ALGORITHM - String similarity score/hash

后端 未结 8 1281
遇见更好的自我
遇见更好的自我 2021-02-01 10:16

Is there a method to calculate something like general \"similarity score\" of a string? In a way that I am not comparing two strings together but rather I get some number/scores

8条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-02-01 10:34

    You may be interested in Hamming Distance. The Python function hamming_distance() computes the Hamming distance between two strings.

    def hamming_distance(s1, s2):
        assert len(s1) == len(s2)
        return sum(ch1 != ch2 for ch1, ch2 in zip(s1, s2))
    

提交回复
热议问题