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 is "ATGCTTCAGAAAGGTCTTAG"
​
Given: A string s of length at most 10000 nucleotides.
​
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:
​
AGCTTTTCATTCTGACTGCAACGGGCAATATGTCTCTGTGTGGATTAAAAAAAGAGTGTCTGATAGCAGC
​
Sample Output: 20 12 17 21
​
Solution:
To count the number of bases we will use the count ( ) method, which counts the number of occurrences of anything in a string. Using the method is really easy:
< >
text = "Oh, woeful, oh woeful, woeful, woeful day!"
print(text.count("woeful"))
4
So now we know how to use the count method we'll simply use it on the DNA string and format our answer beautifully:
< >
string = "AGCTTTTCATTCTGACTGCAACGGGCAATATGTCTCTGTGTGGATTAAAAAAAGAGTGTCTGATAGCAGC"
print(string.count("A"), string.count("C"), string.count("G"), string.count("T"))
Output:
20 12 17 21
Copy and paste the output you get from running your code on the sample data onto the Rosalind answer terminal and submit. Annnd get yourself a cookie!