944,038 Members | Top Members by Rank

Ad:
  • Python Discussion Thread
  • Unsolved
  • Views: 3074
  • Python RSS
Jul 1st, 2006
0

adding values of dictionaries

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

Python Syntax (Toggle Plain Text)
  1. def three2one(prot):
  2. code = {"G" : "6", "A" : "7", "L" : "1", "I" : "4",
  3. "R" : "2", "K" : "3", "M" : "5", "C" : "8",
  4. "Y" : "9", "T" : "10", "P" : "11", "S" : "12",
  5. "W" : "14", "D" : "15", "E" : "16", "N" : "17",
  6. "Q" : "18", "F" : "19", "H" : "20", "V" : "21" , "R" : "22"}
  7.  
  8. newprot = ""
  9. for aa in prot:
  10. newprot+=code.get(aa)
  11. return newprot
  12.  
  13. prot ="""FGYYHFRPTKLRQWEI"""
  14. 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.
Last edited by msaenz; Jul 1st, 2006 at 6:03 pm.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
msaenz is offline Offline
34 posts
since Jul 2006
Jul 2nd, 2006
0

Re: adding values of dictionaries

I assume you want to sum numeric values. Here is slight modification, also removing return statement out of the loop:
Python Syntax (Toggle Plain Text)
  1. def three2one(prot):
  2. code = {"G" : "6", "A" : "7", "L" : "1", "I" : "4",
  3. "R" : "2", "K" : "3", "M" : "5", "C" : "8",
  4. "Y" : "9", "T" : "10", "P" : "11", "S" : "12",
  5. "W" : "14", "D" : "15", "E" : "16", "N" : "17",
  6. "Q" : "18", "F" : "19", "H" : "20", "V" : "21" , "R" : "22"}
  7.  
  8. newprot = 0
  9. for aa in prot:
  10. newprot += int(code.get(aa))
  11. print newprot # just for testing
  12. return newprot
  13.  
  14. prot ="""FGYYHFRPTKLRQWEI"""
  15. # split this up to make testing go better
  16. result = three2one(prot)
  17. print "result =", result
Reputation Points: 404
Solved Threads: 180
Nearly a Posting Virtuoso
bumsfeld is offline Offline
1,422 posts
since Jul 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Python Forum Timeline: Turtle Graphics
Next Thread in Python Forum Timeline: File Modification Time





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC