"Tuples are for heterogeneous data, lists are for homogeneous data."

Lulu of the Lotus-Eaters mertz at gnosis.cx
Wed Mar 12 01:38:03 EST 2003


Arthur <ajsiegel at optonline.net> wrote previously:
|The subject line is a Guido quote from today's dev list.  Is the point
|Guido making performance related, or is it something else?  I have used
|lists extensively for heterogenous data, and wonder what it is I am
|losing by so doing.

I think perhaps you are thinking of "homogeneous" in too narrow a sense.

Data that is homogeneous in a Pythonic way isn't necessarily all
integers, or all strings.  Rather, a list is a bunch of things that you
might loop over, treating each element in the "same way."  Now this same
way might not be entirely the *same*:  for example, if you call a method
on each list element, the method might wind up dispatching to different
code depending on the type of the element.  Or you might even have some
branches within the loop body (if's, try's, etc)... but even then,
there's something "the same" involved in that every element is a
candidate for the same branch conditions, albeit different ones choose
different paths.

Tuples, in contrast, are more often used as *records*, i.e. related
information about a common thing.  The fields of a record need not be
different data *types*, they just represent different information.  For
example, age, weight, and SSN might all be stored as integers, but the
-meaning- of those three positions in a tuple is different.

Yours, Lulu...

--
mertz@  | The specter of free information is haunting the `Net!  All the
gnosis  | powers of IP- and crypto-tyranny have entered into an unholy
.cx     | alliance...ideas have nothing to lose but their chains.  Unite
        | against "intellectual property" and anti-privacy regimes!
-------------------------------------------------------------------------






More information about the Python-list mailing list