
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
Check if a list exists in given list of lists in Python
Lists can be nested, means the elements of a list are themselves lists. In this article we will see how to find out if a given list is present as an element in the outer bigger list.
With in
This is a very simple and straight forward method. We use the in clause just to check if the inner list is present as an element in the bigger list.
Example
listA = [[-9, -1, 3], [11, -8],[-4,434,0]] search_list = [-4,434,0] # Given list print("Given List :\n", listA) print("list to Search: ",search_list) # Using in if search_list in listA: print("Present") else: print("Not Present")
Output
Running the above code gives us the following result −
Given List : [[-9, -1, 3], [11, -8], [-4, 434, 0]] list to Search: [-4, 434, 0] Present
With any
We can also use the any clause where we take an element and test if it is equal to any element present in the list. Of course with help of a for loop.
Example
listA = [[-9, -1, 3], [11, -8],[-4,434,0]] search_list = [-4,434,0] # Given list print("Given List :\n", listA) print("list to Search: ",search_list) # Using in if any (x == search_list for x in listA): print("Present") else: print("Not Present")
Output
Running the above code gives us the following result −
Given List : [[-9, -1, 3], [11, -8], [-4, 434, 0]] list to Search: [-4, 434, 0] Present
- Related Articles
- Check if element exists in list of lists in Python
- Check if a pair with given product exists in Linked list in C++
- Check if value exists in a comma separated list in MySQL?
- How to check if a vector exists in a list in R?
- Convert list into list of lists in Python
- Python - Check if given words appear together in a list of sentence
- Get positive elements from given list of lists in Python
- Python - Check if a list is contained in another list
- How to check if an item exists in a C# list collection?
- Python Check if suffix matches with any string in given list?
- How do make a flat list out of list of lists in Python?
- Check if a triplet with given sum exists in BST in Python
- Python - Convert List of lists to List of Sets
- Custom Multiplication in list of lists in Python
- Convert a list into tuple of lists in Python

Advertisements