Tuples, what are they: read-only lists or heterogeneous data arrays?
googlegroups at tekNico.net
Thu Mar 13 00:02:29 CET 2003
[WARNING: pet peeve ahead]
> FAQ entry 6.15 states:
>> 6.15. Why are there separate tuple and list data types?
>> This is done so that tuples can be immutable while lists are
There's more than that. The tutorial states:
"Tuples have many uses. For example: (x, y) coordinate pairs, employee
records from a database, etc."
I was using MySQLdb, and naturally enough, it returns tuples. I built
another tuple with the values from one field for a number of records,
and I wanted the index of the record with a particular value, so I
reached for a tuple.index() method, and guess what? There is no such
I went to Google and searched through c.l.py., and to my
disappointment, found these discussions:
PROP: tuple.index(), tuple.count()
How come tuples don't have an index method?
which led to this Tracker entry:
[ 403693 ] tupleobject.c: implement tuple.index() and tuple.count()
Date: 2001-02-15 05:49
"Why bother? I like the fact that when you want to do list-ish
things you have to use lists. Use list(t).count(x) if you really
want this for a tuple.
"I'm rejecting this in the name of all those users who want Python
to be small."
Sorry, but this makes no sense. I entirely support the notion that a
tuple should be *exactly* like a list, apart from the fact that it is
immutable, so every read-only list method should be available for
It's bad enough to be chided by Lua aficionados because they need just
one type to do what we do with tuples, lists and dictionaries. ;^) We
need no more superflous subtleties.
And no, list(t).index(x) does not qualify. Neither does
Guido, can't we settle this once and for all?
More information about the Python-list