tuple.index(item)

D

David Isaac

Why don't tuples support an index method?
It seems natural enough ...

Thanks,
Alan Isaac
 
R

Robert Kern

Jules said:
Why don't tuples support an index method?

19:27:32:~ $ python
Python 2.3.5 (#2, Jun 19 2005, 13:28:00)
[GCC 3.3.6 (Debian 1:3.3.6-6)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
t = ('a', 'b', 'c')
t[1] 'b'

He means, rather

t.index('b') == 1

as it works for lists.

--
Robert Kern
(e-mail address removed)

"In the fields of hell where the grass grows high
Are the graves of dreams allowed to die."
-- Richard Harter
 
P

Peter Hansen

David said:
Why don't tuples support an index method?
It seems natural enough ...

This question has been posed several (many?) times in the past. See the
archives for more detail, but basically the answer that is usually given
is this:

Tuples are intended to be used somewhat like C "structs", or Pascal
"records", which is to say they should contain heterogeneous sequences
of information for which the concept of ".index()" is fairly
meaningless. They are _not_ generally intended to be used as "read-only
lists", and that's basically why .index() wasn't defined for them.

Another answer that probably follows close on the heels of that one is
along the lines of "patches are always welcome", but I honestly don't
know if a patch to add this would be accepted. Probably checking
Sourceforge for past patches would give an answer, since it seems likely
someone has already tried.

-Peter
 
R

Raymond Hettinger

[David Isaac]
[Peter Hansen]
This question has been posed several (many?) times in the past. See the
archives for more detail, but basically the answer that is usually given
is this:

Tuples are intended to be used somewhat like C "structs", or Pascal
"records", which is to say they should contain heterogeneous sequences
of information for which the concept of ".index()" is fairly
meaningless. They are _not_ generally intended to be used as "read-only
lists", and that's basically why .index() wasn't defined for them.

Another answer that probably follows close on the heels of that one is
along the lines of "patches are always welcome", but I honestly don't
know if a patch to add this would be accepted. Probably checking
Sourceforge for past patches would give an answer, since it seems likely
someone has already tried.

Executive summary: Guido likes it the way it is. Someday, he may
change his mind. Probably not.


Raymond Hettinger
 

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,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top