tuple.index(item)

2005-07-11 Thread David Isaac
Why don't tuples support an index method?
It seems natural enough ...

Thanks,
Alan Isaac


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: tuple.index(item)

2005-07-11 Thread Jules Dubois
On Monday 11 July 2005 15:23, David Isaac [EMAIL PROTECTED]
([EMAIL PROTECTED]) 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.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: tuple.index(item)

2005-07-11 Thread Robert Kern
Jules Dubois wrote:
 On Monday 11 July 2005 15:23, David Isaac [EMAIL PROTECTED]
 ([EMAIL PROTECTED]) 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
[EMAIL PROTECTED]

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

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: tuple.index(item)

2005-07-11 Thread Peter Hansen
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
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: tuple.index(item)

2005-07-11 Thread Raymond Hettinger
[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

-- 
http://mail.python.org/mailman/listinfo/python-list