[Python-ideas] list.index() extension
Cameron Simpson
cs at zip.com.au
Sun Apr 5 01:44:10 CEST 2009
On 05Apr2009 11:36, Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:
> 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.
Isn't it trivially built on top of itertools.takewhile?
--
Cameron Simpson <cs at zip.com.au> DoD#743
http://www.cskk.ezoshosting.com/cs/
More information about the Python-ideas
mailing list