SV: SV: [Tutor] Why use tuples?

Danny Kohn danny.kohn@systematik.se
Thu, 20 Sep 2001 22:08:14 +0200


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=20
| would have been natural for me to be able to with a datatype of=20
| this nature. So does the statement
| >
| > if col[ColType] =3D=3D IU32:
| >
| > where ColType is a tuple does not work. It is counter intuitive=20
| but I guess I have to get used to not using tuples.
|=20
| 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.
=20
| ---
| >>> a=3D{}
| >>> a[(1,2)]=3D3
| >>> a
| {(1, 2): 3}
| >>>

/Danny