[Tutor] string object into reference
Victor Bouffier
victor at grupocdm.com
Tue Jan 17 23:31:28 CET 2006
Pujo,
I think your solution does not address Kirk's problem. You don't mention
the addition of surface areas. If for any reason he had more than two
types of amino acids, then he would need to use a dictionary for the
totals, with each key being a specific amino acid.
The actual steps to follow are:
1. open the file to read
2. initialize the dictionary to empty
3. for each line in the file
4. see if the key for that amino acid already \
exists in the dictionary
5. if it does not exist, create a new dictionary \
key for that new amino acid, and initialize it \
to zero
6. add the surface area of the current line to the \
corresponding dictionary key
7. print the totals dictionary
Kirk, I would write the program (would take me less time), but the idea
is for yo uto learn to program in Python ;-)
Post your code for review.
Regards.
Victor
On Tue, 2006-01-17 at 22:08 +0100, Pujo Aji wrote:
> Hello Kirk,
>
> If I'm not mistaken your idea is referencing two columns: first column
> is your acid name and the later is your surface area.
> Later you want to connect the surface area if you name the acid name.
> If that what you want another question arises... is your acid name is
> unique.
> If it is you can make dictionary types.
>
> A csb
> B dsk
> C dsk
>
> you can create
> mydic = []
> mydic['A'] = 'csb'
> mydic['B'] = 'dsk'
> mydic['C'] = 'dsk'
>
> you have to transform the file into a list and after that start
> building the dictionary variable.
>
> After this dictionary variable is filled. you can get the surface area
> by typing the acid name such as:
> print mydic['A'] # will result 'csb'
>
> Cheers,
> pujo
>
> On 1/17/06, Kirk Vander Meulen <kvander11 at gmail.com> wrote:
> Hi, just joined. I've got a question that I'm guessing
> there's a ridiculously easy answer to, but I'm having trouble
> (no excuses, I'm just dumb!)...
>
> My problem is I want to make a string object into a reference
> to another object. To be more specific, I'm reading through a
> text file of amino acids. The first item on each line is the
> amino acid name, and a later item is its exposed surface area.
> For each amino acid, I want to add up the surface area as I go
> through the text file. So what I'm doing is, for each line,
> assigning the reference 'residue' to the amino acid name. I'd
> like to then make the string referred to by 'residue' (eg,
> 'CYS' or 'TRP') a reference to an object that I will
> subsquently increment by the surface area value.
>
> Thanks for any help. Perhaps I just need to be pointed to a
> relevent thread or given the correct words to search for in
> the archives or manual.
>
> Kirk
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
More information about the Tutor
mailing list