python统计列表中个元素出现各次数

  • Post author:
  • Post category:python


from collections import Counter

Counter(a)

a = [9, 9, 3, 1, 1, 2]

result = Counter(a)

print(result)

或者

for x in a:
    if a.count(x)>1:
        print(x)

#



版权声明:本文为hengcall原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。