473,468 Members | 1,294 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

tuple.index(item)

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

Thanks,
Alan Isaac
Jul 21 '05 #1
4 1170
On Monday 11 July 2005 15:23, David Isaac <ai*****@verizon.net>
(<ArBAe.6857$Zy6.4547@trnddc04>) wrote:
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'

It seems natural enough ...


It does to me, too.
Jul 21 '05 #2
Jules Dubois wrote:
On Monday 11 July 2005 15:23, David Isaac <ai*****@verizon.net>
(<ArBAe.6857$Zy6.4547@trnddc04>) wrote:
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
rk***@ucsd.edu

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

Jul 21 '05 #3
David Isaac wrote:
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
Jul 21 '05 #4
[David Isaac]
Why don't tuples support an index method?
It seems natural enough ...

[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

Jul 21 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: | last post by:
I need to copy/print the Index window of VS .NET 2003 help but since it is a list we cannot select multiple lines. Does anyone know if there is a utility which would do this, or a way to do it?
4
by: midlothian | last post by:
Hello Is there a way to get the index of an item in an array? For instance, if I have: MyArray = Array("NY","CT","TX","NM") ....can I see what position CT is in the array? Thanks
0
by: kara18 | last post by:
Hi, am trying to create a hash tables of words and their signatures eg acert crater , here acert is the index while the crater is the value. so how would I computer an int key from...
1
by: Giovanni Toffoli | last post by:
Hi, I'm not in the mailing list. By Googling, I stepped into this an old post: (Thu Feb 14 20:40:08 CET 2002) of Jeff Shannon:...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.