Immutable sequence types lacking index() method

A

Anne Wangnick

Dear all,

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?

Regards,
Sebastian Wangnick
 
P

Peter Hansen

Anne said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top