Complete the function, count_bases(s). It takes as input a DNA sequence as a string, s. It should compute the number of occurrences of each base (i.e., 'A', 'C', 'G', and 'T') in s. It should then return these counts in a dictionary whose keys are the bases.



Answer :

Answer:

The function is as follows:

def count_bases(DNA_str):

   retDNA = {}

   for i in DNA_str:

       if i in retDNA:

           retDNA[i]+=1

       else:

           retDNA[i] = 1

   return retDNA

Step-by-step explanation:

This defines the function

def count_bases(DNA_str):

This initializes a dictionary

   retDNA = {}

This iterates through the dictionary

   for i in DNA_str:

If an item exists in the dictionary

       if i in retDNA:

The count is updated by 1

           retDNA[i]+=1

Otherwise

       else:

The count is set to 1

           retDNA[i] = 1

This returns the DAN

   return retDNA