10 examples of 'python remove duplicates from list' in Python

Every line of 'python remove duplicates from list' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
58def remove_duplicates(l):
59 return [list(x) for x in set(tuple(x) for x in l)]
162def remove_duplicates(l):
163 """Remove duplicates from a list (but keep the order)."""
164 seen = set()
165 results = []
166 for e in l:
167 if e not in seen:
168 results.append(e)
169 seen.add(e)
170 return results
76def remove_duplicates (self):
77 # Assumes list has been sorted!
78 for i in range(len(self.files) - 1, 0, -1):
79 if self.files[i] == self.files[i - 1]:
80 del self.files[i]
155def remove_duplicates(self, list_):
156 """Returns a list without duplicates based on the given ``list``.
157
158 Creates and returns a new list that contains all items in the given
159 list so that one item can appear only once. Order of the items in
160 the new list is the same as in the original except for missing
161 duplicates. Number of the removed duplicates is logged.
162 """
163 self._validate_list(list_)
164 ret = []
165 for item in list_:
166 if item not in ret:
167 ret.append(item)
168 removed = len(list_) - len(ret)
169 logger.info('%d duplicate%s removed.' % (removed, plural_or_not(removed)))
170 return ret
1def remove_duplicates(seq):
2 seen = set()
3 seen_add = seen.add
4 return [x for x in seq if not (x in seen or seen_add(x))]
484def deduplicate(lst):
485 i = 0
486 while i < len(lst):
487 if lst[i] in lst[0 : i]:
488 lst.pop(i)
489 i -= 1
490 i += 1
491 return lst
73def _duplicates(a: List[int]) -> List[int]:
74 seen = set()
75 dupes = []
76 for x in a:
77 if x not in seen:
78 seen.add(x)
79 else:
80 dupes.append(x)
81 return dupes
8def remove_duplicates(head):
9 if head is None:
10 return
11
12 current_node = head
13
14 while current_node and current_node.next:
15 if current_node.val == current_node.next.val:
16 current_node.next = current_node.next.next
17 else:
18 current_node = current_node.next
19
20 return head
1463def duplicates(iterable):
1464 seen, dups = set(), set()
1465 for i in iterable:
1466 if i not in seen:
1467 seen.add(i)
1468 else:
1469 dups.add(i)
1470 return dups
21def remove_duplicate_data(dictionary_value):
22 """
23 Removes duplicates from lists in a dictionary mapping keys to lists
24
25 Args:
26 dictionary_value: A dictionary mapping keys to iterable objects
27
28 Returns:
29 A dictionary mapping orignal keys to list conatining unique elements of list of elements they mapped to in
30 remove_duplicate_data
31
32 Example:
33 remove_duplicate_data({"A": [1, 2, 3, 1, 1], "B": [100, 200, 300, 200]})
34
35 Output:
36 {"A": [2, 3, 1], "B": [100, 200, 300]}
37
38 """
39 dictionary_unique = defaultdict(list)
40 for key in dictionary_value:
41 dictionary_unique[key] = list(set(dictionary_value[key]))
42 return dictionary_unique

Related snippets