Immutable sequence types lacking index() method

Discussion in 'Python' started by Anne Wangnick, Aug 31, 2004.

  1. 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
    Anne Wangnick, Aug 31, 2004
    #1
    1. Advertising

  2. Anne Wangnick

    Peter Hansen Guest

    Anne Wangnick wrote:

    > 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.
    Peter Hansen, Aug 31, 2004
    #2
    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. Torsten Mohr

    why are some types immutable?

    Torsten Mohr, Jan 16, 2005, in forum: Python
    Replies:
    7
    Views:
    292
    Fredrik Lundh
    Jan 17, 2005
  2. Replies:
    2
    Views:
    356
  3. Bernard Lim

    Immutable and Mutable Types

    Bernard Lim, Mar 17, 2008, in forum: Python
    Replies:
    16
    Views:
    635
    Terry Reedy
    Mar 19, 2008
  4. Inquisitive Scientist
    Replies:
    3
    Views:
    488
    Mark Lawrence
    Jul 16, 2010
  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:
    269
    Tomasz Chmielewski
    Mar 4, 2008
Loading...

Share This Page