How to find the index of sublist that contains an element in Python

1 Answer

0 votes
sublists = [[1,2,3], [4,5,6], [7,8,9], [10,11,12]]

element = 8

index = [element in n for n in sublists].index(True)

print(index)



'''
run:

2

'''

 



answered Feb 27, 2023 by avibootz
...