Tuple question

Mel Wilson mwilson at the-wire.com
Thu Sep 2 22:10:52 CEST 2004


In article <mailman.2783.1094152072.5135.python-list at python.org>,
Gandalf <gandalf at geochemsource.com> wrote:
>>Note that while .index() makes sense for some sequences,
>>such as strings and lists, it doesn't make sense for the
>>way in which tuples are "supposed to be used", which is
>>as collections of heterogeneous data and not usually as
>>simply read-only lists.
>
>Why it is not useful to have an index() method for collections of heterogeneous data?

   Since the data are heterogenous, they're interpreted
according to their positions in the tuple.  In a tuple of
name, address, city:

        ('Marlene Stewart Street', 'Lois Lane', 'Margaret Bay')

It makes no sense to exchange elements, or treat one like
another, no matter that they're all strings, and no matter
what you think they look like.  Just finding the value 'Lois
Lane' in the tuple doesn't tell you what 'Lois Lane' means.

   All of which is belied by our recent experience of rows
of database fields kicked off by a row of column labels:

        ('name', 'address', 'city')
        ('Marlene Stewart Street', 'Lois Lane', 'Margaret Bay')
        ('Cecil Rhodes', 'Frank Court', 'Saint John')

Then my first and only reaction is to turn the whole mess into a
list of dictionaries and forget about the list/tuple distinction
for the rest of the day.

        Regards.        Mel.



More information about the Python-list mailing list