 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- 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 Row with any Boolean True
When it is required to extract row with any Boolean True, a list comprehension is used along with the ‘any’ operator.
Below is a demonstration of the same −
Example
my_tuple = [[False, True], [False, False], [True, False, True], [False]] print("The tuple is :") print(my_tuple) my_result = [row for row in my_tuple if any(element for element in row)] print("The result is ") print(my_result)  Output
The tuple is : [[False, True], [False, False], [True, False, True], [False]] The result is [[False, True], [True, False, True]]
Explanation
- A list of list is defined and displayed on the console. 
- A list comprehension is used to check if any element is present in the list. 
- The ‘any’ operator gives a True or False result. 
- This is converted to a list and is assigned to a variable. 
- This is the output that is displayed on the console. 
Advertisements
 