in a simple list following check is trivial:
x = [1, 2, 3]
2 in x -> True
x = [[1, 2, 3], [2, 3, 4]]
2 in x -> False
True
Try this, using the built-in any
function. It's the most idiomatic solution, and it's also efficient, because any
short-circuits and stops as soon as it finds the first match:
x = [[1, 2, 3], [2, 3, 4]]
any(2 in sl for sl in x)
=> True