tuple.index()

Tim Golden tjgolden at gmail.com
Fri Dec 15 07:57:59 EST 2006


[Christoph Zwerschke]

> And can somebody explain what is exactly meant with
> "homogenous data"?

This seems to have been explained a few times
recently :) Basically, if you have a "list of xs"
and remove one item from it, it is still a "list of xs",
where "xs" might be people, coordinate-pairs, numbers
or whatever made sense to you. If you have a tuple
containing, say, a 2d coordinate pair, and remove something
from it, it's no longer a coordinate pair. If you add one to it,
it's something else as well (perhaps a 3d coord?)

A typical example of their combined use is a set of
rows returned from a database: each row is a tuple
of fields, the same as all other such rows, and removing
or adding a field would make no sense. However, add
a new row to the list and it remains a list of rows.

Now you can take this or leave it within Python. You
can but mixed values into a list so it isn't really a list
of "xs" unless "x" is just "thing". Likewise you can use
a tuple to hold a list of identical things although you
can't add to it or take away.

> Concretely speaking, which data type should I use
> for coordinate tuples? Usually, tuples are used. Does this mean that I
> should better use lists from now on because all the components have the
> same type?

This would seem to be slightly false logic (and very
possibly used tongue-in-cheek). Heterogeneous data
doesn't mean that each item *has* to be different, merely
that they *may* be.

TJG




More information about the Python-list mailing list