Sometimes, while working with Python list, we might have a problem in which we need to find that a list is a Matrix or a list contains list as it’s element. This problem can come in Data Science domain as it involves use of Matrices more than often. Let’s discuss certain way in which this task can be performed.
Method : Using
any() + isinstance()
The combination of above functions can be used to perform this task. The
any() is used to check for each of the occurrence and
isinstance() is used to check for list.
The original list is : [[5, 6], 6, , 8, 10] Does list contain nested list ? : True
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.
- Python | Check if a nested list is a subset of another nested list
- Python | Pair and combine nested list to tuple list
- Python | Convert a nested list into a flat list
- Python | Find maximum length sub-list in a nested list
- Python | Convert given list into nested list
- Python | Convert string List to Nested Character List
- Python - Test for empty Nested Records
- Nested List Comprehensions in Python
- Python | Intersection of two nested list
- Python | Remove all duplicates and permutations in nested list
- Python | Convert list of nested dictionary into Pandas dataframe
- Python | How to copy a nested list
- Python | Find the sublist with maximum value in given nested list
- Python | Split nested list into two lists
- Python | Remove duplicates from nested list
- Python | Remove all occurrences in nested list
- Python | Column wise sum of nested list
- python | Nested List Intersection Matrix Product
- Python - Value nested grouping on List
- Python - Nested Records List from Lists
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.