Newbie Q on searching lists

Wojtek Walczak gminick at hacker.pl
Sun Nov 24 04:40:56 EST 2002


Dnia Sun, 24 Nov 2002 09:33:15 +0000 (UTC), Wojtek Walczak napisał(a):
> Dnia Sat, 23 Nov 2002 05:45:55 GMT, Kenny Tilton napisał(a):
>> I see the index method on lists throws an error if the element sought is 
>> not found. I was hoping it would return None.
> Yes, you're right, but it's easy to walk around:
...and of course you can still use try/except statements:

a=[1,2,3]
try:
   print a.index(4)
except ValueError:
   print 'not found'

-- 
[ ] gminick (at) underground.org.pl  http://gminick.linuxsecurity.pl/ [ ]
[ "Po prostu lubie poranna samotnosc, bo wtedy kawa smakuje najlepiej." ]



More information about the Python-list mailing list