So let's say I have this array:
array = [[1,2,3],[4,5,6],[7,8,9]]
and I want to get the index of an internal array containing 5, for example. So in this case, the returned index I want is 1.
I tried ind = array.index(5), but I fully understand why this does not work, since the value in brackets must exactly match the element of the array. Another way I did this is
counter = 0
for each in array:
if 5 in each: break
else: counter = counter + 1
and it worked well for what I want, but I wanted to check if there is a simpler and clearer way to do this. Thanks
source
share