In this we are going to see a basic program of hamming distance calculator between two strings and two integers in Python Programming Language.
# The Hamming distance between two strings of equal length is
# the number of positions at which the corresponding symbols are different.
def str_hamming_distance(str1, str2):
return sum(c1 != c2 for c1, c2 in zip(str1, str2))
def int_hamming_distance(n1, n2):
return bin(n1 ^ n2).count('1')
print(str_hamming_distance('abc', 'acd'))
print(int_hamming_distance(4, 9))
# Coded By DHIRAJ SHELKE
#ENJOY CODING
Post a Comment
FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP