myList = [[1, 2], [3, 4], [5, 6]] def index_2d(myList, v): for i, x in enumerate(myList): if v in x: return i, x.index(v) print(index_2d(myList, 3)) # you get # (1, 0)
Here is what the above code is Doing:
1. enumerate(myList) returns a list of tuples, where each tuple is of the form (index, element).
2. i is the index, and x is the element.
3. if v is in x, then we return the index and the index of v in x.