gpt4 book ai didi

python - 将核苷酸转换为相应的 DNA 序列

转载 作者:太空宇宙 更新时间:2023-11-04 06:59:32 26 4
gpt4 key购买 nike

我正在用 Python 做作业。我必须找到一个函数或程序将这个列表转换为相应的 DNA 序列。

bases_list = ['Adenosine', 'Guanine', 'Thymine', 'Cytosine', 'Thymine', 'Adenosine', 'Guanine', 'Cytosine', 'Thymine', 'Adenosine', 'Guanine']

print(dna)

AGTCTAGCTAG #the output

我想也许我可以做一个定义函数来将这些碱基转换为相应的字母。我怎样才能做到这一点?有任何想法吗?

PS:最近才开始学python,希望大家多多帮助:)

最佳答案

是的,有几个!正如您不久前开始的那样,让我们​​做一些简单的事情:

bases_list = ['Adenosine', 'Guanine', 'Thymine', 'Cytosine', 'Thymine', 'Adenosine', 'Guanine', 'Cytosine', 'Thymine', 'Adenosine', 'Guanine']

dna = "" # You begin with the dna empty

for sequence in bases_list: # you go throw every chain
dna += sequence[0] # you add the first letter with the op [0] of lists

print(dna) # finally print

你可以在这里阅读循环的基础 https://wiki.python.org/moin/ForLoop

关于python - 将核苷酸转换为相应的 DNA 序列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47036012/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com