I recently failed an interview in which I was thrown a Python coding question out of the blue. I'm currently learning Python, and if I came upon the same question again or a similar question I want to be able to answer it.
The question was as follows:
Write a function which takes as its input a string containing the letters: [A, C, G, T]; and outputs all the 3-letter subsequences found in the input and the frequency with which they occur. For example, if the input string was "ACTACTTAC", the output would be something like:
ACT: 2 CTA: 1 TAC: 2 CTT: 1 TTA: 1
I came up with some ideas after the fact and I had wondered if a solution like this works, or is there a better way of doing it?
def Determine_DNA(dna_list):
n = len(dna_list[0])
A = [0]*n
T = [0]*n
G = [0]*n
C = [0]*n
for dna in dna_list:
for index, base in enumerate(dna):
if base == 'A':
A[index] += 1
elif base == 'C':
C[index] += 1
elif base == 'G':
G[index] += 1
elif base == 'T':
T[index] += 1
return A, C, G, T