I am trying to get the index of an element in nested lists in python - for example [[a, b, c], [d, e, f], [g,h]] (not all lists are the same size). I have tried
[[a, b, c], [d, e, f], [g,h]]
suppose your list is like this:
lst = [['a', 'b', 'c'], ['d', 'e', 'f'], ['g','h']] list_no = 0 pos = 0 for x in range(0,len(lst)): try: pos = lst[x].index('e') break except: pass list_no = x
list_no gives the list number and pos gives the position in that list
list_no
pos