关于字符串:Python计算DNA核苷酸

Python counting DNA nucleotides

本问题已经有最佳答案,请猛点这里访问。

Problem

A string is simply an ordered collection of symbols selected from some
alphabet and formed into a word; the length of a string is the number
of symbols that it contains.

An example of a length 21 DNA string (whose alphabet contains the
symbols 'A', 'C', 'G', and 'T') is "ATGCTTCAGAAAGGTCTTACG."

Given: A DNA string s

of length at most 1000 nt.

Return: Four integers (separated by spaces) counting the respective number of times that the symbols 'A', 'C', 'G', and 'T'
occur in s

Sample Dataset

1
AGCTTTTCATTCTGACTGCAACGGGCAATATGTCTCTGTGTGGATTAAAAAAAGAGTGTCTGATAGCAGC

Sample Output

1
20 12 17 21

有人能帮我在Mac上为python3编写代码吗?对不起,我完全不习惯Python


相当容易。

1
2
3
4
from collections import Counter
s = 'AGCTTTTCATTCTGACTGCAACGGGCAATATGTCTCTGTGTGGATTAAAAAAAGAGTGTCTGATAGCAGC'
a = Counter(s)
print (a)

计数器('T':21,'A':20,'G':17,'C':12)