List index - why ?

Peter Hansen peter at engcorp.com
Thu Nov 27 11:18:54 EST 2003


Kepes Krisztian wrote:
> 
> The string object have a method named "index", and have a method named
> "find".
> Why don't exists same method in the list object ?

It does:

Python 2.3.2 (#49, Oct  2 2003, 20:02:00) [MSC v.1200 32 bit (Intel)] on win32
>>> l = [1, 2, 3]
>>> l = list('abcdefg')
>>> l
['a', 'b', 'c', 'd', 'e', 'f', 'g']
>>> l.index('d')
3

.find() doesn't exist on lists, perhaps because nobody has asked for it
and presented a good use case.  It seems to me quite rare that somebody 
needs to search for a sublist in a list, and you can already search for
individual elements with "in".


> Same thing is the deleting.
> I think, this method is missing from strings, and lists.

Strings are immutable, and you can already delete elements
from lists.  Or did I miss something...  your request was
a little confusing.

-Peter




More information about the Python-list mailing list