A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://mail.python.org/pipermail/python-dev/2004-April/044378.html below:

[Python-Dev] iter.index()

[Python-Dev] iter.index()Bob Ippolito bob at redivi.com
Sun Apr 18 22:08:25 EDT 2004
On Apr 18, 2004, at 9:53 PM, Christian Stork wrote:

> Hi,
>
> I wanted to do something like
>
>     i = itertools.chain(list1, list2).index(elem)
>
> but that gave me
>
>     ...
>     AttributeError: 'itertools.chain' object has no attribute 'index'
>
> If I use the operator module it works just fine.
>
>     i = operator.indexOf(itertools.chain(list1, list2), elem)
>
> Why not add the index method to iterator objects?  Of course, 
> internally
> only next() is used by the default implementation.

An iterator mutates each time you call its next().  Your call to 
indexOf does one of three things: exhaust some of your iterator and 
return a useless integer, exhaust all of your iterator and raise an 
exception, or never return.

If you want an object that acts like a list, you should use a list.

-bob


More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4