Python | Remove duplicates in Matrix Last Updated : 24 Mar, 2023 Summarize Comments Improve Suggest changes Share Like Article Like Report While working with Python Matrix, we can face a problem in which we need to perform the removal of duplicates from Matrix. This problem can occur in Machine Learning domain because of extensive usage of matrices. Let's discuss certain way in which this task can be performed. Method : Using loop This task can be performed in brute force manner using loops. In this, we just iterate the list of list using loop and check for the already presence of element, and append in case it's new element, and construct a non-duplicate matrix. Python3 # Python3 code to demonstrate working of # Removing duplicates in Matrix # using loop # initialize list test_list = [[5, 6, 8], [8, 5, 3], [9, 10, 3]] # printing original list print("The original list is : " + str(test_list)) # Removing duplicates in Matrix # using loop res = [] track = [] count = 0 for sub in test_list: res.append([]); for ele in sub: if ele not in track: res[count].append(ele) track.append(ele) count += 1 # printing result print("The Matrix after duplicates removal is : " + str(res)) Output : The original list is : [[5, 6, 8], [8, 5, 3], [9, 10, 3]] The Matrix after duplicates removal is : [[5, 6, 8], [3], [9, 10]] Time Complexity: O(n*n) where n is the number of elements in the list “test_list”. Auxiliary Space: O(n), where n is the number of elements in the new res list Comment More infoAdvertise with us Next Article Python | Remove duplicates in Matrix M manjeet_04 Follow Improve Article Tags : Python Python Programs Python list-programs Python matrix-program Practice Tags : python Similar Reads Python - Remove Kth Index Duplicates in Tuple Sometimes, while working with Python records, we can have a problem in which we need to remove all the tuples, which have similar Kth index elements in list of records. This kind of problem is common in day-day and web development domain. Let's discuss certain ways in which this task can be performe 7 min read Python - Remove Duplicates from a List Removing duplicates from a list is a common operation in Python which is useful in scenarios where unique elements are required. Python provides multiple methods to achieve this. Using set() method is most efficient for unordered lists. Converting the list to a set removes all duplicates since sets 2 min read Python | Remove duplicates from nested list The task of removing duplicates many times in the recent past, but sometimes when we deal with the complex data structure, in those cases we need different techniques to handle this type of problem. Let's discuss certain ways in which this task can be achieved. Method #1 : Using sorted() + set()Â Th 5 min read Python | Removing duplicates from tuple Many times, while working with Python tuples, we can have a problem removing duplicates. This is a very common problem and can occur in any form of programming setup, be it regular programming or web development. Let's discuss certain ways in which this task can be performed. Method #1 : Using set() 4 min read Removing Duplicates of a List of Sets in Python Dealing with sets in Python allows for efficient handling of unique elements, but when working with a list of sets, you may encounter scenarios where duplicates need to be removed. In this article, we will see how we can remove duplicates of a list of sets in Python. Remove Duplicates of a List of S 2 min read Like