Problem
Figure 2. The Hamming distance between these two strings is 7. Mismatched symbols are colored red.
Given two strings ss and tt of equal length, the Hamming distance between ss and tt, denoted dH(s,t)dH(s,t), is the number of corresponding symbols that differ in ss and tt. See Figure 2.
Given: Two DNA strings ss and tt of equal length (not exceeding 1 kbp).
Return: The Hamming distance dH(s,t)dH(s,t).
Sample Dataset
GAGCCTACTAACGGGAT
CATCGTAATGACGGCCT
Sample Output
7代码:
###Counting Point Mutations ###
def CPM(s, t):
l = min(len(s), len(t))
result = 0
for i in range(0, l):
if s[i] <> t[i]:
result += 1
print resultif __name__ == "__main__":
fh = open ("C:\\Users\\hyl\\Desktop\\rosalind_hamm.txt")
s = fh.readline()
for line in fh:
t = line
CPM(s, t)