Skip to main content
 首页 » 编程设计

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

2025年05月04日10shihaiming

我正在用 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