I need to find the substring of s
that is closest to a string by Hamming distance and have it return a tuple of the index of the closest substring, the Hamming distance of the closest substring to p
, and the closest substring itself.
I have this code so far:
def ham_dist(s1, s2):
if len(s1) != len(s2):
raise ValueError("Undefined")
return sum(ch1 != ch2 for ch1, ch2 in zip(s1, s2))
But I am confused on how I would figure this out:
Your function should return
(1,2,'bcef')
because the closest substring is'bcef'
, it begins at index 1 ins
, and its Hamming distance top
is 2.In your function, you should use your
ham_dist
function from part (a). If there is more than one substring with the same minimum distance top
, return any of them.