- 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 program to remove row with custom list element
When it is required to remove row with custom list element, a list comprehension and the ‘any’ operator are used.
Below is a demonstration of the same
my_list = [[14, 3, 11], [66, 27, 8], [31, 12, 21], [11, 16, 26]] print("The list is :") print(my_list) check_list = [3, 10, 19, 29, 20, 15] print("The check list is :") print(check_list) my_result = [row for row in my_list if not any(element in row for element in check_list)] print("The result is :") print(my_result)
The list is : [[14, 3, 11], [66, 27, 8], [31, 12, 21], [11, 16, 26]] The check list is : [3, 10, 19, 29, 20, 15] The result is : [[66, 27, 8], [31, 12, 21], [11, 16, 26]]
- A list of integers is defined and is displayed on the console.
- A list of integers is defined as ‘check_list’ and is displayed on the console.
- A list comprehension is used to iterate over the elements and the ‘any’ operator is used.
- Here, it is checked to see if an element in the row matches with the elements provided in the ‘check_list’
- If yes, the row is stored in a list.
- This is assigned to a variable.
- This is displayed as output on the console.
- Java Program to remove an element from List with ListIterator
- Python program to remove rows with duplicate element in Matrix
- Python Program to remove a specific digit from every element of the list
- How to remove an element from a list in Python?
- Python - Convert List to custom overlapping nested list
- Python Program to print element with maximum vowels from a List
- Custom list split in Python
- Python program to remove Duplicates elements from a List?
- Python program to remove elements at Indices in List
- Python Program to Remove Palindromic Elements from a List
- Remove Element in Python
- Python Program to sort rows of a matrix by custom element count
- Java Program to remove the last row from a table with DefaultTableModel
- Java Program to remove the first row from a table with DefaultTableModel
- How to remove an element from a list by index in Python?