index() of sequence type?
Stefan Behnel
stefan_ml at behnel.de
Thu Feb 7 08:19:17 EST 2008
Neal Becker wrote:
> I see list has index member, but is there an index function that applies to
> any sequence type?
Like this?
def find_index(seq, value):
try:
find_index = seq.index
except AttributeError:
def find_index(value):
for i,v in enumerate(seq):
if v == value: return i
raise ValueError("index(seq, x): x not in sequence")
return find_index(value)
> If not, shouldn't there be?
I don't see the need.
Stefan
More information about the Python-list
mailing list