Solution:
Here c
is the index not the list that you are looking. Because you cannot iterate through an integer, you are obtaining that error.
>>> myList = ['a','b','c','d']
>>> for c,element in enumerate(myList):
... print c,element
...
0 a
1 b
2 c
3 d
You are trying to check if 1
is in c
, which does not make sense
Based on the OP's comment It must print "t" in case there is a 0 in a row and there is not a 1 in the row.
Alter if 1 not in c
to if 1 not in row
for c, row in enumerate(matrix):
if 0 in row:
print("Found 0 on row,", c, "index", row.index(0))
if 1 not in row: #change here
print ("t")
More clarification: The row
variable retain a single row itself, ie [0, 5, 0, 0, 0, 3, 0, 0, 0]
. The c
variable apprehend the index of which row it is. ie, in case row
contains the 3rd row in the matrix, c = 2
. Keep in mind that c
is zero-based, for example the first row is at index 0, second row at index 1 etc.
Cast, Cast, Cast.
word = 'stuff'
blur = 12344566
word in str(blur)
This will output false successfully saying you whether stuff can be figured out inside the now string ‘12344566’. And currently for a more objective example.
array = ['Foo','Bar', 1]
for element in array:
print(element)
if 'sandwich' in element:
print('Found the sandwich')
Here we can view all elements of the array are printed since the error happens on the third element. One will never trace a string in an int. You can eliminate checking types and error handling by wrapping element in str() to cast it as a string in case we come across any unruly data types.
array = ['Foo','Bar', 1]
for element in array:
print(element)
if 'sandwich' in str(element):
print('Found the sandwich'