
- DCN Tutorial
- Data Comm & Networks Home
- DCN - Overview
- DCN - Computer Network Types
- DCN - Network LAN Technologies
- DCN - Computer Network Topologies
- DCN - Computer Network Models
- DCN - Computer Network Security
- Physical Layer
- DCN - Physical Layer Introduction
- DCN - Digital Transmission
- DCN - Analog Transmission
- DCN - Transmission media
- DCN - Wireless Transmission
- DCN - Multiplexing
- DCN - Network Switching
- Data Link Layer
- DCN - Data Link Layer Introduction
- DCN - Error detection and Correction
- DCN - Data Link Control & Protocols
- Network Layer
- DCN - Network Layer Introduction
- DCN - Network Addressing
- DCN - Routing
- DCN - Internetworking
- DCN - Network Layer Protocols
- Transport Layer
- DCN - Transport Layer Introduction
- DCN - Transmission Control Protocol
- DCN - User Datagram Protocol
- Application Layer
- DCN - Application Layer Introduction
- DCN - Client-Server Model
- DCN - Application Protocols
- DCN - Network Services
- DCN Useful Resources
- DCN - Quick Guide
- DCN - Useful Resources
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.
Example
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)
Output
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]]
Explanation
- 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.
- Related Articles
- 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
- Python Program to Remove All Occurrences of an Element in an Array/List
- How to remove an element from a list in Python?
- Python Program to print element with maximum vowels from a List
- Python - Convert List to custom overlapping nested list
- 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
- Python Program to Remove a Subset from a List
- Python program to remove null value from a list
- Python Program to sort rows of a matrix by custom element count
- How to remove an element from a list by index in Python?
- Python Program to Remove the last element from an Array

Advertisements