SV: SV: [Tutor] Why use tuples?

Ignacio Vazquez-Abrams ignacio@openservices.net
Thu, 20 Sep 2001 17:09:55 -0400 (EDT)


On Thu, 20 Sep 2001, Danny Kohn wrote:

> Excuse be for being ignorant but this is the tutor group :-)
>
> | -----Ursprungligt meddelande-----
> | Fran: tutor-admin@python.org [mailto:tutor-admin@python.org]For Ignacio
> | Vazquez-Abrams
> | Skickat: den 20 september 2001 20:03
>
> | > Ok. But then again I can not use a tuple as an index which
> | would have been natural for me to be able to with a datatype of
> | this nature. So does the statement
> | >
> | > if col[ColType] == IU32:
> | >
> | > where ColType is a tuple does not work. It is counter intuitive
> | but I guess I have to get used to not using tuples.
> |
> | Have you _tried_ using a tuple as an index?
>
> Yes, in the above example. It didn't work out. Your example below is with a dictionary. I understand that it works there. But does it work generally thorughout Python and if so, how do I get it to work? I expected that it would make no difference to Python if ColType is an integer, a list element or a tuple. If this is so, please enlighten me.

Ah, I see what you mean.

All sequence types (lists, tuples, or strings) can only use integers or slices
for indexes. Dictionaries can use any immutable type (integers, strings, or
tuples).

-- 
Ignacio Vazquez-Abrams  <ignacio@openservices.net>