[Python-ideas] list.index() extension
Benjamin Peterson
benjamin at python.org
Sun Apr 5 01:51:17 CEST 2009
Greg Ewing <greg.ewing at ...> writes:
>
> Christian Heimes wrote:
>
> >>def index(self, obj, predicate=operator.eq):
> >> for idx, item in enumerate(self):
> >> if predicate(item, obj):
> >> return idx
> >> raise IndexError
>
> This looks more like it belongs in the itertools module,
> if there isn't something there already that does it.
There's `next(itertools.ifilter(some_list, lambda x: x is my_obj))`, but that
returns the object and not the index as I want.
More information about the Python-ideas
mailing list