James Stroud wrote: > 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.
I just found that there is indeed some mentioning in the FAQ here: http://www.python.org/doc/faq/general/#why-are-there-separate-tuple-and-list-data-types But it is a bit vague, too, and does not mention whether there is any difference in efficiency which would be interesting to know as well. It would be nice if somebody with more knowledge about the internals could overhaul and supplement that answer in the FAQ. A link to this in the tutorial or other parts of the standard doc where tuples and lists are discussed would be also helpful. >> 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. So in which cases exactly should one make exceptions? Python experts probably decide this from their "gut feelings" but it would be nice to have a more complete "rule of thumb" or decision guidance for non-experts that is mentioned somewhere in the docs, too: Must be hashable for use as dict key or set element --> tuple "Inhomogenous" in some meaning of the word --> tuple ... (fill in the details) --> tuple everything else --> list Maybe we can agree on something concrete here. -- http://mail.python.org/mailman/listinfo/python-list