0

I try to check if there is the integer 0 in my array. There are similar topics around here but none of them is exactly what I need. At first I thought this: Fastest way to check if a value exist in a list was what I was looking for but it doesn't work with multidimensional arrays (or lists of lists as you call them in Python) I believe.

So here is what I got so far:

myList = [[0,0,0],[0,0,0],[0,0,0]] 

while 0 in myList: # here is the problem. This statement is never true 
                   # but 'while [0,0,0]' is
    # do stuff

print(myList)

I can think of a solution that iterates through all the Elements using 2 loops but I was hoping there was an easier way.

I appreciate your help!

geets
  • 51
  • 5

1 Answers1

1

chain could be helpful

from itertools import chain
0 in chain(*[[0,0,0],[0,0,0],[0,0,0]] )
mad_
  • 8,121
  • 2
  • 25
  • 40