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#SECTION001030
try:
do_something_0(M_l
> One way is to check the length of each dimension. Does any body
> know a simpler way?
No need to check the length of the list:
"""
>>> foo = [0, 1, 2, [3, 4, 5, 6, 7, [8, 9, 10]]]
>>> isInNested(0, foo)
True
>>> isInNested(11, foo)
False
>>> isInNested(3, foo)
True
>>> isInNested(8, foo)
True
""
On Thu, Jul 19, 2007 at 02:43:13PM -0700, Arash Arfaee wrote:
> One way is to check the length of each dimension. Does any body
> know a simpler way? is there any way to check if "IndexError: list
> index out of range" happened or going to happen and stop program
> from terminating?
If I understan
Is there any way to check if an item in specific location in a multiple
dimension nested exist? For example something like:
if M_list[line][row][d] exist:
do_something_0
else:
do_something_1
Certainly:
try:
M_list[line][row][d]
except IndexError:
do_something_1
else:
do_somethin