tuple.index()
James Stroud
jstroud at mbi.ucla.edu
Fri Dec 15 23:38:41 EST 2006
Christoph Zwerschke wrote:
> Maybe there would be less dispute if this dogma/convention(?) "Tuples
> are for heterogeneous data, list are for homogeneous data" would be
> written down somewhere in the tutorial, reference or in PEP8, so people
> would be aware of it.
This is a good idea. It has taken me a while to begin using them in this
manner. I have been more or less forced to by the design of the language
and I confess that the intended usage of each is pretty natural.
But until this thread, I only had a latent understading of their
intended use. Now it is much clearer to me, though it seems kind of
late. I don't think an explicit explanation is in Learning Python (which
is the book I used to learn python).
It seems like such an fundamental principle should be in *all* of the
introductory texts, much like the process for defining a function is in
all introductory texts. I don't think PEPs, the language reference, or
inclusion in a single introductory text somewhere would be enough for
one to point at and say "you should have read this".
(Well, I'm in the process of reading the internet right now, but I just
haven't gotten to PEP 646 or python-dev from 1993. I estimate I'll get
to these in a few dozen years.)
If I recall correctly, Learning Python emphasized the practical
differences between tuples and lists and did not elaborate on the
philosophy of their usage. I seem to remember an emphasis on efficiency
and how tuples hold an advantage.
> And can somebody explain what is exactly meant with "homogenous data"?
> That the type of the elements is the same in some technical or
> philosophical meaning?
Hopefully homogenous means that all of the objects in the list share a
common interface. To enforce this interface would require the interface
definition in the initialization of a list, etc., which would not be
consistent with python duck typing and would require that interfaces be
added to the language.
> 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?
I don't think that all homogenous structures should be lists. This is
not the same as saying that all lists should be homogenous.
James
--
James Stroud
UCLA-DOE Institute for Genomics and Proteomics
Box 951570
Los Angeles, CA 90095
http://www.jamesstroud.com/
More information about the Python-list
mailing list