index() of sequence type?

Stefan Behnel stefan_ml at
Thu Feb 7 14:19:17 CET 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):
          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.


More information about the Python-list mailing list