Given a binary matrix, print all unique rows of the given matrix. Order of row printing doesn’t matter.
Input: mat = [[0, 1, 0, 0, 1], [1, 0, 1, 1, 0], [0, 1, 0, 0, 1], [1, 1, 1, 0, 0]] Output: (1, 1, 1, 0, 0) (0, 1, 0, 0, 1) (1, 0, 1, 1, 0)
We have existing solution for this problem please refer link. We can solve this problem in python quickly using Set data structure. Approach is very simple.
- We are given list of boolean values list, put all rows (list) in set because set contains unique values.
- Since list is an unhashable type for set because it is mutable that’s why first we convert each row (list) into tuple then we put all tuple in set.
- Resultant set will contain only unique valued tuples (row).
(1, 1, 1, 0, 0) (0, 1, 0, 0, 1) (1, 0, 1, 1, 0)
- Print unique rows in a given boolean matrix
- Python Counter| Find duplicate rows in a binary matrix
- Python | Remove tuples having duplicate first value from given list of tuples
- Python | Remove tuples from list of tuples if greater than n
- Python | Count tuples occurrence in list of tuples
- Python | Remove duplicate tuples from list of tuples
- Python | Find the tuples containing the given element from a list of tuples
- Python | Unique values in Matrix
- Python | Combining tuples in list of tuples
- A Boolean Matrix Question
- Remove first X rows and columns from a matrix
- Common elements in all rows of a given matrix
- Interchange elements of first and last rows in matrix
- Find all permuted rows of a given row in a matrix
- Count all sorted rows in a matrix
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.