python中输出两条长度一致序列碱基不同的个数

 

001、方法1

root@PC1:/home/test# ls
test.py
root@PC1:/home/test# cat test.py               ## 测试程序
#!/usr/bin/python

str1 = "GAGCCTACTAACGGGAT"                     ## 两天等长序列
str2 = "CATCGTAATGACGGCCT"

count = 0;

for i in range(len(str1)):
    if str1[i] != str2[i]:
        count += 1

print(count)
root@PC1:/home/test# python test.py            ## 执行程序
7

 

002、方法2

root@PC1:/home/test# ls
test.py
root@PC1:/home/test# cat test.py                     ## 测试程序
#!/usr/bin/python

str1 = "GAGCCTACTAACGGGAT"
str2 = "CATCGTAATGACGGCCT"

count = sum([i != j for i,j in zip(str1,str2)])
print(count)
root@PC1:/home/test# python test.py                   ## 执行程序
7

 

参考:https://mp.weixin.qq.com/s?__biz=MzIxMjQxMDYxNA==&mid=2247484182&idx=1&sn=b9827db4bd9c4eebcd48d546f50b4226&chksm=9747ca8fa0304399e708fab685019647a8ed6649bcbb320b95b776ed8cd66ee967fdac9a5e6c&scene=178&cur_album_id=1635727573621997580#rd

posted @ 2022-08-18 15:35  小鲨鱼2018  阅读(200)  评论(0编辑  收藏  举报