Answers for "python efficiently find duplicates in list"

9

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
4

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
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 "python efficiently find duplicates in list"

Python Answers by Framework

Browse Popular Code Answers by Language