- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Python – Extract rows with Complex data types
When it is required to extract rows with complex data types, the ‘isinstance’ method and list comprehension are used.
Below is a demonstration of the same
my_list = [[13, 1,35], [23, [44, 54], 85], , [75, (81, 2), 29, 7]] my_result = [row for row in my_list if any(isinstance(element, list) or isinstance(element, tuple) or isinstance(element, dict) or isinstance(element, set) for element in row)] print("The list is :") print(my_list) print("The resultant list is :") print(my_result)
The list is : [[13, 1, 35], [23, [44, 54], 85], , [75, (81, 2), 29, 7]] The resultant list is : [[23, [44, 54], 85], [75, (81, 2), 29, 7]]
A list of list is defined and is displayed on the console.
A list comprehension is used to iterate over the list and see if the element belongs to the ‘list’ type using the ‘isinstance’ method.
This is assigned to a variable.
This is displayed as the output on the console.
- Python program to extract rows from Matrix that has distinct data types
- Python – Extract Particular data type rows
- Python – Extract rows with Even length strings
- Python – Extract Paired Rows
- Python program to extract rows with common difference elements
- Python Program to Extract Rows of a matrix with Even frequency Elements
- Standard Data Types in Python
- How to extract data from a string with Python Regular Expressions?
- How to Extract Wikipedia Data in Python?
- How to extract unique combination of rows in an R data frame?
- Java String Concatenation with Other Data Types.
- Which data types are immutable in Python?
- Get tuple element data types in Python
- Difference between fundamental data types and derived data types