一、查找数列重复元素---count()
>>> list = [1,2,2,2,2,3,3,3,4,4,4,4] >>> set = set(list) >>> for item in set: print("the %d has found %d" %(item,list.count(item))) #输出 #the 1 has found 1 #the 2 has found 4 #the 3 has found 3 #the 4 has found 4
二、查找重复元素,使用 Counter
>>> from collections import Counter >>> Counter([1,2,2,2,2,3,3,3,4,4,4,4])
#输出 #Counter({2: 4, 4: 4, 3: 3, 1: 1})
参考自:
[1] 作者:范恒
https://www.cnblogs.com/AaronFan/p/6084175.html