Nothing is being added to my output list. Can anyone explain why

58 Views Asked by At
  def translateGene(dnaStrand, startPos, stop):
        protein = []
        def aminoAcid(dnaCodon):
            return(dnaCode[dnaCodon])
            maybeCodon = [dnaStrand[i:i +3] for i in range (startPos, stop-1)]
            for j in maybeCodon:
                if j == (dnaCode[dnaCodon]):
                    protein.append(j)
                return protein

This function takes a string, an integer as a starting index in the string and an integer as an ending index in the string. The idea of the program is to split the string into 3 letter acronyms with the letters from the starting point to the endpoint. Then it should look up a given dictionary for all the acronyms and if they are present in the dictionary, add their results to the protein list but my code above leaves protein empty. The function Aminoacid has been created for me to use as part of this function, but I'm not sure if I've called it correctly. My code above leaves protein empty.

Can anyone explain why. Any help is greatly appreciated.

1

There are 1 best solutions below

0
On

First, I think that your code should be indenting adjusted to:

def translateGene(dnaStrand, startPos, stop):
    protein = []
    
    def aminoAcid(dnaCodon):
        return (dnaCode[dnaCodon])
    
    maybeCodon = [dnaStrand[i:i + 3] for i in range(startPos, stop - 1)]
    for j in maybeCodon:
        if j == (dnaCode[dnaCodon]):
            protein.append(dnaCodon)
    return protein

Then test it.

and notice that, It seems that you have two global dnaCode,dnCodon, which is known before calling the function.