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