I am a newbie at programming, and I have been learning Python for a very short time. Below, I tried to write a code, which counts nucleotides in a sample DNA sequence (A question from ROSALIND).
nucleotides=['A','C','G','T']
string='AGCTTTTCATTCTGACTGCAACGGGCAATATGTCTCTGTGTGGATTAAAAAAAGAGTGTCTGATAGCAGC'
for n in nucleotides:
a = string.count (n)
print ("The count for",n,"is:",a)
The output is:
The count for T is: 21
The problem is that my code prints only the result of last element in "nucleotides" array, which is 'T'. I know that I am asking a silly question but I tried to find an answer by searching on both here and web, and I wasn't successful. This is why, I would be very appreciated if you could correct the code and made an explanation to me why my loop did not print counts for each nucleotide.
Many thanks!