Answers for "how to find only the duplicates from a list in python"

11

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
0

python efficiently find duplicates in list

from collections import Counter

def get_duplicates(array):
    c = Counter(array)
    return [k for k in c if c[k] > 1]
Posted by: Guest on January-26-2022

Code answers related to "how to find only the duplicates from a list in python"

Python Answers by Framework

Browse Popular Code Answers by Language