Re: How to check if an item exist in a nested list

2007-07-19 Thread Miles
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

Re: How to check if an item exist in a nested list

2007-07-19 Thread zacherates
> 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 ""

Re: How to check if an item exist in a nested list

2007-07-19 Thread Will Maier
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

Re: How to check if an item exist in a nested list

2007-07-19 Thread Matt McCredie
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