tuple.index(item)

Discussion in 'Python' started by David Isaac, Jul 11, 2005.

  1. David Isaac

    David Isaac Guest

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

    Thanks,
    Alan Isaac
     
    David Isaac, Jul 11, 2005
    #1
    1. Advertising

  2. David Isaac

    Jules Dubois Guest

    On Monday 11 July 2005 15:23, David Isaac <>
    (<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.
     
    Jules Dubois, Jul 12, 2005
    #2
    1. Advertising

  3. David Isaac

    Robert Kern Guest

    Jules Dubois wrote:
    > On Monday 11 July 2005 15:23, David Isaac <>
    > (<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


    "In the fields of hell where the grass grows high
    Are the graves of dreams allowed to die."
    -- Richard Harter
     
    Robert Kern, Jul 12, 2005
    #3
  4. David Isaac

    Peter Hansen Guest

    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
     
    Peter Hansen, Jul 12, 2005
    #4
  5. [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
     
    Raymond Hettinger, Jul 12, 2005
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Michal Mikolajczyk
    Replies:
    1
    Views:
    832
    Larry Bates
    Apr 20, 2004
  2. Jeff Epler
    Replies:
    0
    Views:
    1,027
    Jeff Epler
    Apr 20, 2004
  3. Gregor Horvath

    Why tuple with one item is no tuple

    Gregor Horvath, Mar 15, 2005, in forum: Python
    Replies:
    37
    Views:
    864
    Antoon Pardon
    Mar 30, 2005
  4. Alan G Isaac
    Replies:
    5
    Views:
    423
    Colin J. Williams
    Aug 14, 2009
  5. Tomasz Chmielewski

    sorting index-15, index-9, index-110 "the human way"?

    Tomasz Chmielewski, Mar 4, 2008, in forum: Perl Misc
    Replies:
    4
    Views:
    337
    Tomasz Chmielewski
    Mar 4, 2008
Loading...

Share This Page