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 | Check if a list exists in given list of lists
- Python | Check if a list is contained in another list
- Python | Check if list is sorted or not
- Python | Check if all elements in a List are same
- Python | Check if a given object is list or not
- Python | Check if one list is subset of other
- Python | Check if all the values in a list are less than a given value
- Python | Check whether a list is empty or not
- Python | Check if list is strictly increasing
- Python | Check if all the values in a list that are greater than a given value
- Python | Check if list contains consecutive numbers
- Python | Check if given words appear together in a list of sentence
- Python | Check for Nth index existence in list
- Python | Check if all elements in a list are identical
- Python | Check if list contains all unique elements
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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.