【发布时间】:2019-10-12 02:52:18
【问题描述】:
在这个问题中,给你一个字符串 s,它代表一个 DNA 字符串。字符串 s 由符号“A”、“C”、“G”和“T”组成。长度为 21 的 DNA 字符串的一个示例是“ATGCTTCAGAAAGGTCTTACG”。
你的任务是编写一个代码来计算每个符号“A”、“C”、“G”和“T”在 s 中出现的次数。您的代码应该生成一个包含 4 个整数的列表并将其打印出来。
# Here is the DNA string:
s = 'AGCTTTTCATTCTGACTGCAACGGGCAATATGTCTCTGTGTGGATTAAAAAAAGAGTGTCTGATAGCAGC'
# Type your code here
错误地,我写的字符串在字母之间有空格。
s='A G C T T T T C A T T C T G A C T G C A A C G G G C A A T A T G T C T C T G T G T G G A T T A A A A A A A G A G T G T C T G A T A G C A G C'
list_of_symbols=s.split(sep=' ')
list_of_symbols
word_count_dictionary={}
for A in list_of_symbols:
if A not in word_count_dictionary:
word_count_dictionary[A]=1
else:
word_count_dictionary[A]+=1
【问题讨论】:
-
将您的字符串附加到列表并使用 Counter 方法:stackoverflow.com/questions/2600191/…
标签: python python-3.x count symbols