7 examples of 'python count duplicates in list' in Python

Every line of 'python count duplicates in 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
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
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]
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
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]
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

Related snippets