Python | Check if list is Matrix
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
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. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course