list prob

Justin Shaw wyojustin at hotmail.com
Tue May 21 20:30:14 EDT 2002


Gabe's solution will work as long as you don't need and exact match.  I
think you are on the right track as long as you aren't afraid to handle an
exception.

try:
    i = list.index("word to search")
except ValueError:
   i = DEFAULT

"Gabe Newcomb" <Gabe.Newcomb at noetix.com> wrote in message
news:mailman.1022018678.1352.python-list at python.org...
string.find() returns -1 if the string isn't found, instead of the
ValueError thrown by string.index()

-----Original Message-----
From: kemu [mailto:kemusoft at hotmail.com]
Sent: Tuesday, May 21, 2002 2:49 PM
To: python-list at python.org
Subject: list prob


I want to search a list if I do list.index("word to search") and the
word
isn't in the list I get an error I don't want to get one from python but
want my own error like word is not in the list how ?
or is there an other way to search the list for strings and if he
doesn't
find one he doesn't print an error ?


--
http://mail.python.org/mailman/listinfo/python-list







More information about the Python-list mailing list