

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
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 program to remove rows with duplicate element in Matrix
When it is required to remove rows with duplicate element in a matrix, a list comprehension and the ‘set’ operator is used.
Example
Below is a demonstration of the same −
my_list = [[34, 23, 34], [17, 46, 47], [22, 14, 22], [28, 91, 19]] print("The list is :") print(my_list) my_result = [element for element in my_list if len(set(element)) == len(element)] print("The result is :") print(my_result)
Output
The list is : [[34, 23, 34], [17, 46, 47], [22, 14, 22], [28, 91, 19]] The result is : [[17, 46, 47], [28, 91, 19]]
Explanation
A list of list is defined and is displayed on the console.
A list comprehension is used to iterate over the elements in the list, and the length of the unique element is compared to the length of every element in the list.
If they are equal, it is stored in the list and assigned to a variable.
This is displayed as the output on the console.
- Related Questions & Answers
- Remove similar element rows in tuple Matrix in Python
- Write Python program to find duplicate rows in a binary matrix
- Write a program in Python to remove first duplicate rows in a given dataframe
- How to remove rows in a Pandas series with duplicate indices?
- Java program to remove the duplicate element in an array
- Python Program to sort rows of a matrix by custom element count
- Python program to remove row with custom list element
- Remove duplicate element in a Java array.
- Python – Remove rows with Numbers
- Find duplicate rows in a binary matrix in C++
- Program to remove duplicate entries in a list in Python
- How to remove duplicate columns from a matrix in R?
- Python – Remove Rows for similar Kth column element
- Python Program to Extract Rows of a matrix with Even frequency Elements
- Program to remove duplicate entries in a linked list in Python
Advertisements