[Python-ideas] list.index() extension
benjamin at python.org
Sun Apr 5 02:39:24 CEST 2009
2009/4/4 Leif Walsh <leif.walsh at gmail.com>:
> Maybe you didn't understand what I meant. Try the following code,
> with your favorite list and object. I promise it works.
> print "The index of the first element that 'is obj' is %d." % (idx
> for idx, elt in enumerate(lst) if elt is obj).next()
> except StopIteration:
> print "obj is not in lst"
Yes, I saw that but it still strikes me as much uglier than necessary.
More information about the Python-ideas