[Python-Dev] Ridiculously minor tweaks?

Guido van Rossum guido@python.org
Wed, 12 Mar 2003 07:48:05 -0500

> > Tuples are for heterogeneous data, list are for homogeneous data.
> > Tuples are *not* read-only lists.
> Oh!
> Did you point that out anywhere, before, and I missed it?

Yes.  I've been saying this for years whenever people would listen
(which is not often :-( )

> Are you thinking of lists as to be really somehow
> being homogeneous data, in a sense to be replacible
> by some array optimization, sometimes, while tuples aren't?

Python is a dynamic language, and you can do whatever you want with
the data structures it gives you.  But when thinking about extending
the language with optional type declarations or automatic type
inference, I always think of the type of a list as "list of T" while I
think of a tuple's type as "tuple of length N with items of types T1,
T2, T3, ..., TN".  So [1, 2] and [1, 2, 3] are both "list of int" (and
"list of Number" and "list of Object", of course) while ("hello", 42)
is a "2-tuple with items str and int" and (42, "hello", 3.14) is a
"3-tuple with items int, str, float".

> I never realized this, and I'm a bit stunned.
> (but by no means negative about it, just surprized)

You learn something new every day. :-)

--Guido van Rossum (home page: http://www.python.org/~guido/)