Contact: aviboots(AT)netvision.net.il
40,886 questions
53,294 answers
573 users
import collections lst = [1, 1, 2, 3, 4, 4, 4, 5, 6, 6, 7, 7, 7, 7] print([item for item, count in collections.Counter(lst).items() if count > 1]) ''' run: [1, 4, 6, 7] '''
import collections lst = [1, 1, 2, 3, 4, 4, 4, 5, 6, 6, 7, 7, 7, 7] duplicates = [item for item, count in collections.Counter(lst).items() if count > 1] print(duplicates) ''' run: [1, 4, 6, 7] '''
import collections lst = [1, 1, 2, 3, 4, 4, 4, 5, 6, 6, 7, 7, 7, 7] count_elements = {i:lst.count(i) for i in lst} for key, value in count_elements.items(): if (value > 1): print(key) ''' run: 1 4 6 7 '''