| | |
adding values of dictionaries
Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Jul 2006
Posts: 34
Reputation:
Solved Threads: 0
Hi everyone,
I am doing a bioinformatics project and I have this code:
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 am doing a bioinformatics project and I have this code:
Python Syntax (Toggle Plain Text)
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.
Last edited by msaenz; Jul 1st, 2006 at 6:03 pm.
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)
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
![]() |
Similar Threads
- confused with the assignment ... need help asap (C++)
- how to do loops for power (C++)
- help with recursion (C++)
- ExpApproximator (Java)
- Passing Value to other page (ASP)
- hi, need help with sorting (Python)
- XML Serialization (C#)
- Arrays (Java)
Other Threads in the Python Forum
- Previous Thread: Turtle Graphics
- Next Thread: File Modification Time
Views: 2058 | Replies: 1
| Thread Tools | Search this Thread |
Tag cloud for Python
accessdenied address ansi backend beginner changecolor class code conversion coordinates copy curves customdialog dan08 dictionary directory dynamic edit examples excel feet file float font format ftp function generator getvalue gui halp homework i/o images import info input ip java line linux list lists loop mouse mysql newb number numbers output panel parsing path port prime print program programming projects py2exe pygame pyqt python queue random rational recursion recursive schedule screensaverloopinactive scrolledtext searchingfile server ssh stamp statictext string strings sudokusolver table terminal text thread threading time tkinter tlapse tuple tutorial type ubuntu unicode url urllib urllib2 variable whileloop windows write wxpython






