a = [[1,2,3],[4,5,6]]
I would like to get 0 for 1,2 and 3 and to get 1 for 4, 5 and 6.
of course I can do something like that:
def get_index(my_list, my_item):
for i, j in enumerate(my_list):
if my_item in j:
return i
raise ValueError("Item not in any list")
Is there a better way of doing it?
Updated Answer:
This is an improved version of my original answer, thanks to input from zenply, the OP.
Result: