Immutable sequence types lacking index() method

Peter Hansen peter at engcorp.com
Tue Aug 31 15:19:36 EDT 2004


Anne Wangnick wrote:

> I don't get why the index() method is only defined for mutable sequence
> types. This is not what I expected. Shouldn't this be added in Python? Is
> there such a PEP already?

I don't believe such simple changes require a PEP.  They do,
however, require someone actually requesting it (which is to
say not here, but in the appropriate Sourceforge tracker)
and someone else deciding it should be done and maybe a
third person actually doing it.  I suspect no one has done
the first step yet, though before you do, check past requests
to see if it was requested and rejected.

Note that the only reason .index() exists even for lists (as
opposed to merely for strings) was because I** requested it,
and someone implemented it (I believe it was Raymond Hettinger
but my memory is notoriously poor).

Note that while .index() makes sense for some sequences,
such as strings and lists, it doesn't make sense for the
way in which tuples are "supposed to be used", which is
as collections of heterogeneous data and not usually as
simply read-only lists.  Of course, that debate is still
ongoing and there is always the argument that one has to
turn lists into tuples to use them as dictionary keys,
so the only way to resolve the question is to request the
change (but not here) and see what happens.

-Peter

** I think it was me, but I'm not even sure about that.



More information about the Python-list mailing list