list index()

Marshall T. Vandegrift llasram at gmail.com
Thu Aug 30 09:53:53 EDT 2007


zzbbaadd at aol.com writes:

> What's with the index() function of lists throwing an exception on not
> found? Let's hope this is rectified in Python 3. If nothing else, add
> a function that doesn't throw an exception. There are a million
> situations where you can have an item not be in a list and it is not
> an exception situation.

The Python string types have both the method `index()` which throws an
exception and the method `find()` which implements the same behavior but
returns -1 for not-found substrings.  I would naively have assumed the
`list` type to provide both as well, but it provides only `index()`.

Anyone know the reason for this lack of parallelism?

-Marshall




More information about the Python-list mailing list