rosalind练习题六

# Problem

# Given two strings s and t of equal length, the Hamming distance between s and t, denoted dH(s,t),

# is the number of corresponding symbols that differ in s and t. See Figure 2.

# Given: Two DNA strings s and t of equal length (not exceeding 1 kbp).

# Return: The Hamming distance dH(s,t)

# Sample Dataset

# GAGCCTACTAACGGGAT

# CATCGTAATGACGGCCT

# Sample Output

# 7

# 这道题要求我们计算两个等长的 DNA 序列之间的 Hamming 距离,也就是这两个序列在同一位置上不同碱基的数量。

# 基础代码:

a = "GAGCCTACTAACGGGAT"

b = "CATCGTAATGACGGCCT"

m = 0

for i in range(len(a)):

    if a[i] != b[i]:

        m += 1

print(m)

# 用函数优化

def sum_base(a, b):

    """

    计算两个等长的 DNA 序列之间的 Hamming 距离

    """

    count = 0

    for i in range(len(a)):

        if a[i] != b[i]:

            count += 1

    return count

print(sum_base(a, b))

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容