How to check if an element is present in a nested list in Python

1 Answer

0 votes
nestedlist = [[1, 2, 3], [1, 5], [6, 1, 8, 9, 10], [1, 9, 10, 10], [1]]

print(any(3 in sub_list for sub_list in nestedlist))
print(any(891 in sub_list for sub_list in nestedlist))


'''
run:

True
False

'''

 



answered Feb 9, 2025 by avibootz
...