error handling with python lists
I have lists being created by a program and depending if a value exists I
want to do something further. If not, I want to pass.
For example:
a=[1,2,3,4,5]
if a.index(6):
print "in"
I get the following
Traceback (most recent call last):
File "c.py", line 6, in <module>
if a.index(6):
ValueError: 6 is not in list
How do I search for a value in a python list and do something if I find
the number?
No comments:
Post a Comment