How to find all duplicate elements and their values in a python list?

Need a function that, for example, for the list [10, 10, 23, 10, 123, 66, 78, 123] return {10: 3, 123: 2}.
July 8th 19 at 15:48
1 answer
July 8th 19 at 15:50
Solution
So
from collections import Counter
my_list = [10, 10, 23, 10, 123, 66, 78, 123]
c = Counter(my_list)
>>> c
Counter({10: 3, 123: 2, 66: 1, 78: 1, 23: 1})
>>> type(c)
<class 'collections.counter'>
d = dict(c)
>>> d
{10: 3, 123: 2, 66: 1, 78: 1, 23: 1}
>>> type(d)
<class 'dict'></class></class>
Gracefully =) - Emmy_Armstrong commented on July 8th 19 at 15:53

Find more questions by tags Python