I want to get the index of the "4" in the nested list, it is working cause I suppress the error. any idea for a alternative?
a = [[1,2,3],[4,5,6],[7,8,9]]
for i in range(len(a)):
try:
index = a[i].index(4)
print(i, index)
except:
pass
>Solution :
This is code that won’t throw an error and doesn’t use index() function.
for i in range(len(a)):
for j in range(len(a[i])):
if a[i][j] == 4:
print("Found at", i, j)
break