[Tutor] Dictionaries [Was: Re: string object into reference]

Victor Bouffier victor at grupocdm.com
Wed Jan 18 05:48:50 CET 2006


Hi Danny,

On Tue, 2006-01-17 at 16:03 -0800, Danny Yoo wrote:
> > > 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.
> 

> These kind of "bulk" questions are fairly easy to answer if we collect all
> the key-value pairs in a single dictionary container, because we're just
> asking that one container.
> 
> But it's much harder to answer this if we use individual variables for
> each key-value pair, since we don't tell the system that those variables
> are somehow related as a group --- as far as Python knows, they're just
> disconnected variables.
> 
I couldn't agree more. I love using dictionaries. I don't know why I
suggested individual variables instead of the usage of a dictionary in
the first place.

> 
> The terminology that the original poster uses ("references to another
> object") sounds a lot like the original usage of symbolic "soft"
> references in Perl.
> (http://www.perl.com/doc/manual/html/pod/perlref.html)
> 
> Perl programmers, for the most part, avoid them now because they're so
> error prone. So if the original poster is thinking about symbolic
> references, then we should encourage the poster to look into dictionaries,
> since dictionaries are a fairly direct replacement for that usage.
> 
I did not know Perl programmers were moving away from references. That's
new to me, and an interesting point.

On the other hand, Kirk's comment about "references to another object"
takes us into a discussion over references, when we actually should be
focusing on Perl's hashes (or references to hashes for that matter).

Or better still, get away from Perl and start programming in Python and
use dictionaries instead! ;-)


> Best of wishes!
> 

Thanks a lot.
Victor





More information about the Tutor mailing list