[Python-Dev] find method for lists

Guido van Rossum guido@digicool.com
Wed, 25 Jul 2001 12:37:09 -0400


> This has probably been discussed before, but why doesn't the list object
> support a find method?  Seems like if a non-exception-raising index method
> is good enough for strings, it should be good enough for lists as well.  I
> realize I can use "l.count(x) and l.index(x)" to avoid the possible
> ValueError.  (Or maybe it's strings that shouldn't have find, but can't be
> deleted not for code breakage reasons?)
> 
> I'm mostly just curious.  Am I missing something?

List searching is much less common, and the string functions (both
index() and find()) have different semantics: they look for
substrings, while list.index() only searches for a particular item.

With lists, if you need this, you're probbly using the wrong
datastructure.  With strings, substring matching is a standard
pattern.

--Guido van Rossum (home page: http://www.python.org/~guido/)