Hi everyone,
I am doing a bioinformatics project and I have this code:

def three2one(prot):                                            
    code = {"G" : "6", "A" : "7", "L" : "1", "I" : "4",
            "R" : "2", "K" : "3", "M" : "5", "C" : "8",
            "Y" : "9", "T" : "10", "P" : "11", "S" : "12",
            "W" : "14", "D" : "15", "E" : "16", "N" : "17",
             "Q" : "18", "F" : "19", "H" : "20", "V" : "21" , "R" : "22"}
 
    newprot = ""
    for aa in prot:
        newprot+=code.get(aa)
        return newprot
 
prot ="""FGYYHFRPTKLRQWEI"""
print three2one(prot)

what I am trying to do is take a protein sequence in prot variable and have the values that are assigned to those letters in the dictionary to add them. I would really appreciate anyone's help thank you! Currently it only takes the first letter value...this is not homework this is a separate indepedant project of learning.

I assume you want to sum numeric values. Here is slight modification, also removing return statement out of the loop:

def three2one(prot):                                            
    code = {"G" : "6", "A" : "7", "L" : "1", "I" : "4",
            "R" : "2", "K" : "3", "M" : "5", "C" : "8",
            "Y" : "9", "T" : "10", "P" : "11", "S" : "12",
            "W" : "14", "D" : "15", "E" : "16", "N" : "17",
            "Q" : "18", "F" : "19", "H" : "20", "V" : "21" , "R" : "22"}
 
    newprot = 0
    for aa in prot:
        newprot += int(code.get(aa))
        print newprot  # just for testing
    return newprot
 
prot ="""FGYYHFRPTKLRQWEI"""
# split this up to make testing go better
result = three2one(prot)
print "result =", result
This question has already been answered. Start a new discussion instead.