Check if an item is in a nested list

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

Leave a Comment