[Tutor] referencing a dictionary

Sean Blakey sblakey@freei.com
Mon, 17 Jul 2000 13:08:41 -0700

On Mon, Jul 17, 2000 at 07:50:13PM +0000, brian callahan wrote:
> hi,
> hows it going.  i had a quick (hopefully) question about using a dictionary. 
>   my idea is to use a raw_input string, to search a dictionary that contains 
> all the characters in the raw_input string with a value, and then i want to 
> sum the values.  my script is used to take a the amino acid sequence of a 
> protein and then give back the molecular weight.  i've been using the 
> 'learning python' book but im getting impatient.
> thanks for your help,
> brian c.
> ________________________________________________________________________
> Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://www.python.org/mailman/listinfo/tutor

Not sure exactly what your question is, but I'll try to give you some sample

import string
weights = {'A': 5, 'B': 7, 'C': 3}
acids = string.upper(raw_input("Enter the amino acid sequence"))
weight = 0
for acid in acids:
    weight = weight + weights[acid]
print "The molecular weight of this protein is", weight

Is this what you were looking for?

Sean Blakey, sblakey@freei.com
Software Developer, FreeInternet.com
Decaffeinated coffee?  Just Say No.