[Tutor] Distinction between tuples and lists
alan.gauld at btinternet.com
Fri Jan 2 17:41:13 CET 2009
"Roel Schroeven" <rschroev_nospam_ml at fastmail.fm> wrote
> In the point of view taken by Guido and the writer of the blogs
> mentioned before, a tuple of x, y coordinates is not homogeneous,
> heterogeneous. Both x and y do have the same type, but that's not
> point. The point is that the meaning of the two elements is
> It makes, for example, no sense to sort such a tuple.
Yes, I spotted Guido making that point shortly after posting :-)
I guess its more a case of thinking of tuples as lightweight records
rather that strictly heterogenuous(*) types (which is a somewhat moot
issue in Python). So the significant point is that in a tuple each
has a meaning specific to its position.
The big problem is that they are also immutable which greatly
reduces their effectiveness in that role. So the alternatives are
a class - for possibly a single instance - or use a list as a writable
(*) Although heterogenuous does not really debar same type
items but the focus on type is I suspect misleading in terms of
understanding the role of tuples.
Author of the Learn to Program web site
More information about the Tutor