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 @   小鲨鱼2018  阅读(205)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
点击右上角即可分享
微信分享提示