Tuples vs Lists: Semantic difference

Ben Finney bignose+hates-spam at benfinney.id.au
Thu Mar 1 22:17:04 CET 2007

"George Sakkis" <george.sakkis at gmail.com> writes:

> On Feb 28, 10:45 pm, Ben Finney wrote:
> > Tuples are intended for use as heterogeneous data structures [...]
> > Lists are intended for use as homogeneous sequences [...]
> Nice, that's a good summary of the straw man arguments about the
> "true" distinction between tuples and lists.

I'm not sure why you say it's a "straw man argument". I'm presenting
*my* understanding of a position that I also share, in order to defend
it; a straw man argument is a misrepresentation of *another party's*
position for the purpose of appearing to attack that party's position.


Whose position have I misrepresented and attacked?

> Now can you please explain why an "heterogeneous data structure":

> 1) does not support __setitem__, changing the value of an existing
> item from 3 to 4,

In the case of a tuple, because the "value" is conceptually the entire
tuple. To change one of its items would be to create a new value -- so
that's what is supported.

> 2) supports iteration over its ("heterogeneneous") elements, but not
> an index() method

An index() method would imply that the index of an item has some
meaning, such that extracting a single item is meaningful. Since a
tuple represents a single conceptual structural value, to extract one
item is something to be done at the same time as extracting all the

> 3) why using indices rather than names for implied semantics is a
> good idea anyway.

You've already shown that one *doesn't* use an index for accessing
items in a tuple.

> As for addition/removal/insertion of elements not making sense for a
> heterogeneous data structure, have you heard of database schema
> change ?

A database schema change is not an operation one performs with the
expectation that the tuples will remain the same. Thus, one would
expect to discard the old tuples as obsolete and retrieve them from
the relation again, getting new tuples.

> Heterogeneous data structures are well known for several decades
> now; they are commonly spelled "records" though, not tuples, and
> have a more reasonable API to support their semantics.

Python doesn't natively support relational schema operations. It does
natively support tuples. I never professed that the two were the same,
and don't accept that they should be.

 \      "I have never made but one prayer to God, a very short one: 'O |
  `\       Lord, make my enemies ridiculous!' And God granted it."  -- |
_o__)                                                         Voltaire |
Ben Finney

More information about the Python-list mailing list