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
Reputation Points: 404
Solved Threads: 180
Nearly a Posting Virtuoso
Offline 1,422 posts
since Jul 2005