I have a list that looks like this:
a = [[[0.0125, 6.6], [0.0125, 6.65], [0.0125, 6.7], [0.0125, 6.75], [0.0125, 6.8]], [[0.0185, 6.6], [0.0185, 6.65], [0.0185, 6.7], [0.0185, 6.75], [0.0185, 6.8]]]
ie: N
sub-lists (only two here) and M
sub-sub-lists in each sub-list (five in this example). Each element/sub-sub-list is made of two floats.
I need to find the index of a given element, say [0.0185, 6.75]
. In this case the result should be: [1, 3]
.
I can't just apply the .index()
operator on a
since the element is inside one of the sub-lists and since I don't know a priori which one it is I can't loop through the sub-lists applying that operator because it will result in an error if the element is not found.
Add
I tried the answers by zhangxaochen ans DSM in a much larger array (16 sub-lists and 70 sub-sub-lists) to see which one was faster and this is what I got:
DSM: 4.31537628174e-05
zhangxaochen: 0.00113296508789
Since DSM's answer its ~26x faster, I'm selecting that one. Thanks guys!