问题描述
Problem
Figure 2. The Hamming distance between these two strings is 7. Mismatched symbols are colored red.
Given two strings s s s and t t t of equal length, the Hamming distance between s s s and t t t, denoted d H ( s , t ) d_{\mathrm{H}}(s, t) dH(s,t), is the number of corresponding symbols that differ in s s s and t t t. See Figure 2.
Given: Two DNA strings s s s and t t t of equal length (not exceeding 1 kbp).
Return: The Hamming distance d H ( s , t ) d_{\mathrm{H}}(s, t) dH(s,t).
Sample Dataset
GAGCCTACTAACGGGAT
CATCGTAATGACGGCCT
Sample Output
7
题解
对每个字符逐一比较即可
参考代码
with open("rosalind_hamm.txt", "r") as f:
a = f.readline().rstrip()
b = f.readline().rstrip()
ans = 0
for i in range(len(a) - 1):
ans += (a[i] != b[i])
print(ans)
f.close()