Sometimes, while working with Python lists, we can have a problem in which we need to check for a Matrix. This type of problem can have a possible application in Data Science domain due to extensive usage of Matrix. Let’s discuss a technique and shorthand which can be used to perform this task.
Method : Using
isinstance() + all()
This problem can be performed using the combination of above functions. The
all() can be used to check for all the elements of list and
isinstance function checks for the list datatype in list. The logic behind is, every element of list must be a list to qualify it as matrix.
The original list is : [[4, 5], [5, 8], [9, 10]] Is list a Matrix ?: True
- Python | Convert list of string to list of list
- Python | Convert list of tuples to list of list
- Python | Convert List of String List to String List
- Python | Check if a nested list is a subset of another nested list
- Python | Check if a list exists in given list of lists
- Python | Check if a list is contained in another list
- Python - Check List elements from Dictionary List
- Python program to check if the list contains three consecutive common numbers in Python
- Python | Maximum sum of elements of list in a list of lists
- Python List Comprehension | Segregate 0's and 1's in an array list
- Python | Pair and combine nested list to tuple list
- Python | Filter a list based on the given list of strings
- Python | Convert a nested list into a flat list
- Python program to create a list of tuples from given list having number and its cube in each tuple
- Python | Sort list of list by specified index
- Python | Remove all values from a list present in other list
- Python | Sort list according to other list order
- Python | Convert list of strings and characters to list of characters
- Python | Insert list in another list
- Python | Convert a string representation of list into list
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.