,

Python – Hamming Distance


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

def test_hamming_distance():
    s1,s2="0102304", "9375304"
    res = hamming_distance(s1, s2)
    print(res)
    print((s1,list(zip(s1,s2))))


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *