[Python-ideas] Python Users Aren't Perfect

Nick Coghlan ncoghlan at gmail.com
Fri Dec 16 00:06:01 CET 2011

On Fri, Dec 16, 2011 at 7:06 AM, Ned Batchelder <ned at nedbatchelder.com> wrote:
> Where is that in the docs?  Sounds like a patch is needed:
> "lists are for sequences where items need to be added/removed; tuples are
> for sequences/aggregations where items will not be added/removed once the
> tuple is created"
> I don't know if it appears in the docs, but I hear it all the time, and
> Guido has said it
> (http://mail.python.org/pipermail/python-dev/2003-March/033964.html):
> Tuples are for heterogeneous data, list are for homogeneous data.
> Tuples are *not* read-only lists.
> I don't want to get too far off the original point, which was: Python isn't
> as simple as we'd like to thing, and even smart beginners can be tripped up
> by things we've provided to them.

Guido has softened his stance on that point over the years (IIRC, the
question came up explicitly in the discussion over making tuple()
fully conform to the Sequence ABC - you can guess the outcome from the
fact that tuple these days in fact *does* fully conform to that ABC,
including the previously missing index() and count() methods).

So tuples have two valid use cases: as read-only arbitrary-length
sequences of homogeneous data and as fixed-length sequences of
heterogeneous data.

These days, the latter use case is often better served by creating a
collections.namedtuple() definition rather than using a bare tuple


Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia

More information about the Python-ideas mailing list