[Tutor] Distinction between tuples and lists

Roel Schroeven rschroev_nospam_ml at fastmail.fm
Fri Jan 2 14:26:16 CET 2009


Alan Gauld schreef:
> "Kent Johnson" <kent37 at tds.net> wrote
>> For what it's worth, Guido has explicitly said,
>> "Tuples are for heterogeneous data, list are for homogeneous data.
>> Tuples are *not* read-only lists."
> 
> That surprises me, he has always seemed more pragmatist than purist.
> However even Guido saying it doesn't alter the fact that in practice 
> it is not a part of the language, merely a usage pattern.

I think it's more than a usage pattern; I think it is also the idea
behind the design decisions of list and tuple behavior. It's why lists
have index() methods for example, and tuples don't.

> Precisely. That was the point I tried to make earlier that in most
> usage scenarios lists tend to be used homogenously and tuples
> heterogenenously. But there is absolutely nothing in Python that
> mandates it. A good example of a homogenous tuple is a pair of
> values such as a point's x,y coordinates.

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, it's
heterogeneous. Both x and y do have the same type, but that's not the
point. The point is that the meaning of the two elements is different.
It makes, for example, no sense to sort such a tuple.

-- 
The saddest aspect of life right now is that science gathers knowledge
faster than society gathers wisdom.
  -- Isaac Asimov

Roel Schroeven



More information about the Tutor mailing list