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
More Related Contents:
- How to make a dict from n’th indices of tuples in list
- Why does this code for initializing a list of lists apparently link the lists together? [duplicate]
- Access multiple elements of list knowing their index
- Appending the same string to a list of strings in Python
- Python list doesn’t reflect variable change
- Removing item from list causes the list to become NoneType
- Why is [] faster than list()?
- How can I multiply all items in a list together with Python?
- How to unzip a list of tuples into individual lists? [duplicate]
- Remove trailing newline from the elements of a string list
- How to loop through all but the last item of a list?
- Writing a list to a file with Python, with newlines
- How can I convert each item in the list to string, for the purpose of joining them? [duplicate]
- How can I initialize a dictionary of distinct empty lists in Python?
- Extract elements of list at odd positions
- Python: How to remove empty lists from a list? [duplicate]
- How to use python numpy.savetxt to write strings and float number to an ASCII file?
- How to get the n next values of a generator in a list (python)
- python: most elegant way to intersperse a list with an element
- Converting a string that represents a list, into an actual list object
- Merging/adding lists in Python
- how to keep elements of a list based on another list [duplicate]
- Flatten an irregular (arbitrarily nested) list of lists
- How to concatenate (join) items in a list to a single string
- Convert all strings in a list to integers
- “TypeError: ‘type’ object is not subscriptable” in a function signature
- Ellipsis lists […] and concatenating a list to itself [duplicate]
- How can I convert string values from a dictionary, into int/float datatypes?
- Optimal method to find the max of sublist items within list
- In what case would I use a tuple as a dictionary key? [closed]