[Tutor] Creating a complex python object

Danny Yoo dyoo at hkn.eecs.berkeley.edu
Sat Aug 14 01:33:05 CEST 2004

> > Darn - and just today I created a mechanism using a list in which the
> > 1st element is a string and the rest integer. Sigh.
> >
> I've seen the homogeneous vs heterogeneous description of lists and
> tuples, but pure convention doesn't seem to be a very good argument for
> it. There must be a good practical reason

Hi Nik,

Not necessarily "practical".  *grin*

In the math world, mathematicians use tuples just as a programmer uses
structured records.  As a concrete example, when mathematicians talk about
"graphs", they might say something like this:

    A graph G is defined to be a 2-tuple (V, E), where V is a set of
    verticles, and E is a set of edges.

Another concrete example from a mathy point of view is the relational
algebra (the theory behind SQL databases).  According to relational
algebra, a table "relation" is made up of a set of tuples.

Wikipedia has a nice article that talks about the term "tuple" in both
math and computer science contexts:


So that's why we'd say that tuples are heterogeneous things: they've
always been meant to represent fixed-size records.  They are not designed
to expand or contract in size, which is why we'd say that they're
"immutable".  So the way that Python uses tuples isn't really too far from
their original math definition.

> Is it the immutability of the tuple, or the fact you can't use a list as
> a key that's pushed it in that direction, or was it really as simple as
> one guy in the early days saying 'I prefer this convention'?

At least from this point of view, it's not accidental that tuples are
heterogeneous and immutable: that's their definition from years of
mathematical usage.  Don't blame just Guido.  *grin*

Hope this helps!

More information about the Tutor mailing list