Найти дубликаты в списке Python
names = ['name1', 'name2', 'name3', 'name2']
set([name for name in names if names.count(name) > 1])
Eufemiano Fuentes Pérez
names = ['name1', 'name2', 'name3', 'name2']
set([name for name in names if names.count(name) > 1])
>>> your_list = ['one', 'two', 'one']
>>> len(your_list) != len(set(your_list))
True
from collections import Counter
def get_duplicates(array):
c = Counter(array)
return [k for k in c if c[k] > 1]
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]