Answers for "find duplicate elements in list"

8

count the duplicates in a list in python

some_list=['a','b','c','b','d','m','n','n']

 my_list=sorted(some_list)
 
duplicates=[]
for i in my_list:
     if my_list.count(i)>1:
         if i not in duplicates:
             duplicates.append(i)
 
print(duplicates)
Posted by: Guest on January-30-2021
1

duplicate in list python

a = [1,2,3,2,1,5,6,5,5,5]

import collections
print([item for item, count in collections.Counter(a).items() if count > 1])

## [1, 2, 5]
Posted by: Guest on May-21-2020
3

how to check if there are duplicates in a list python

>>> your_list = ['one', 'two', 'one']
>>> len(your_list) != len(set(your_list))
True
Posted by: Guest on December-12-2019

Code answers related to "find duplicate elements in list"

Python Answers by Framework

Browse Popular Code Answers by Language