python——Counter函式統計列表中元素出現次數
阿新 • • 發佈:2021-02-16
不多說了,直接上例子加程式碼!
from collections import Counter
from collections import Counter #匯入Counter函式
a = ["a","b","b","c","c","c"]
print(Counter(a))
b = dict(Counter(a))#轉化成字典
print(b)
print ([key for key,value in b.items() if value > 1]) #只展示重複元素
print ({key:value for key,value in b.items() if value > 1})