[Tutor] Dictionaries
Lloyd Kvam
lkvam@venix.com
Mon, 12 Nov 2001 20:15:14 -0500
If I understodd properly, you could replace:
{1: a,b,c,d,e,f,g,h,i}
with
{1: [a,b,c,d,e,f,g,h,i]}
The square brackets are used to represnt a list. Parentheses are used to
denote a tuple. The parentheses will sometimes be assumed as in your
case. a,b,c == (a,b,c).
Lists are mutable, tuples are not mutable.
dict[1][2] = C will replace c with C in your first list.
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
>
>
--
Lloyd Kvam
Venix Corp.
1 Court Street, Suite 378
Lebanon, NH 03766-1358
voice:
603-443-6155
fax:
801-459-9582