1 from collections import Counter
2
3 a = [1, 2, 3, 4, 3, 2, "奔奔", "benben", "奔奔"]
4 b = dict(Counter(a))
5 # 只展示重复元素
6 print ([key for key,value in b.items() if value > 1])
7 # 展现重复元素和重复次数
8 print ({key:value for key,value in b.items()if value > 1})
运行结果:
[2, 3, '奔奔']
{2: 2, 3: 2, '奔奔': 2}