How to check if an item exist in a nested list

Miles semanticist at gmail.com
Fri Jul 20 00:52:55 EDT 2007


Arash Arfaee wrote:
> is there any way to check if "IndexError: list index out of
> range" happened or going to happen and stop program from terminating?

Use a try/except block to catch the IndexError
http://docs.python.org/tut/node10.html#SECTION0010300000000000000000

try:
    do_something_0(M_list[line][row][d])
except IndexError:
    do_something_1()




More information about the Python-list mailing list