[Python-Dev] iter.index()

Christian Stork python-dev-list at cstork.org
Sun Apr 18 23:26:32 EDT 2004

On Sun, Apr 18, 2004 at 10:50:13PM -0400, Bob Ippolito wrote:
> >Why useless?  It returns the index.  Why do I have to build a new
> >concatinated list (or my own special index function) in order to get
> >that information?
> It returns an index into some sequence that no longer exists.  What 
> good is that?

In my special case, it is essentially a ranking.  I don't need to access
the lists via the index.

> >>exhaust all of your iterator and raise an exception,
> >
> >Yep, just as it would for lists.
> The difference is that the iterator's life is more or less over, 
> there's probably nothing useful you can do with it, but a list is not 
> changed by this operation.

Note that the mathematical function 

    index: Elems -> Integer

has a right to live on its own with the application of list accesses.

> >>If you want an object that acts like a list, you should use a list.
> >
> >I don't see anything inherently "listy" about index().  It just counts
> >how many elements there are to reach elem.  And obviously the
> >functionality is already there in the operator module.  I'm just
> >proposing a little convenience.
> I think it's pretty rare that you would want to know this information 
> at the cost of exhausting some/all of your iterator... and if that 
> really is what you want, then you should just use operator.indexOf.  
> There are MANY iterable types, it's not reasonable to change them all.

If that is the consensus, so be it.  :-)  I'm just proposing it as it's
in the spirit of itertools.  It also eliminates an asymmetry between lists
and iterators as demonstrated by operator.index() which is supposed to
implement the intrinsic operators.  Admittedly, it might not be very

Chris Stork   <>  Support eff.org!  <>   http://www.ics.uci.edu/~cstork/
OpenPGP fingerprint:  B08B 602C C806 C492 D069  021E 41F3 8C8D 50F9 CA2F

More information about the Python-Dev mailing list