[Fwd: Re: [Tutor] Dictionaries]

Lloyd Hugh Allen lha2@columbia.edu
Mon, 12 Nov 2001 20:57:21 -0500


Darn "reply" instead of "reply-to-all"--still not used receiving the
list in not digest-form.

-------- Original Message --------
From: Lloyd Hugh Allen <vze2f978@mail.verizon.net>
Subject: Re: [Tutor] Dictionaries
To: Mike Yuen <myuen@ucalgary.ca>

Have you tried using the data as a tuple? Since tuples are immutable (or
hashable, or something like that), they're allowed to be dictionary
data. Your dictionary in the example below would be

{1: (a,b,c,d,e,f,g,h,i)}

or

{1: ((a,b,c),(d,e,f),(g,h,i))}

or something like that. When you want to play with your data as a list,
send the tuple to list(); when you want to re-store it in the
dictionary, turn it back into a tuple with tuple(). (unless you use the
nested tuple to represent your matrix, in which case you have to be more
creative).

Mike Yuen wrote:
> 
> I have to use dictionaries for this particular portion.  I've got some
> data in the following format:
> 
> 1
>  a b c
>  d e f
>  g h i
> 
> 2
>  j k l
>  m n o
>  p q r
> 
> And so on.
> 
> What I want to do is have 1, 2,... as keys in my dictionary and have each
> of the next 3 rows as the data associated with the keys.  The problem i'm
> having is that dictionaries are immutable add/delete stuff like lists
> meaning I can't get the data to look like:
> 
>         {1: a,b,c,d,e,f,g,h,i}
> 
> So, if I can combine these 3 rows into 1 row, I can manipulate it easier later.
> Any suggestions on how to get around this little dilemma i'm having.
> 
> Thanks,
> M
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor