10 examples of 'finding duplicates in list python' in Python

Every line of 'finding duplicates in list python' 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
this disclaimer
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
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

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
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
105def duplicate_items(items):
106 unique = set(items)
107 counts = {i: items.count(i) for i in unique}
108 return [i for i in counts if counts[i] > 1]
58def remove_duplicates(l):
59 return [list(x) for x in set(tuple(x) for x in l)]
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))]
45def findRemove(listR, value):
46 """used to test if a value exist, if it is, return true and remove it."""
47 try:
48 listR.remove(value)
49 return True
50 except ValueError:
51 return False
1def remove_duplicates(nums):
2 if not nums:
3 return 0
4
5 i = 1
6 cur = nums[0]
7 for n in nums:
8 if n != cur:
9 nums[i] = cur = n
10 i += 1
11
12 return i

Related snippets