字典出现字符的次数
from collections import defaultdict, Counter
num = ['1', '1', '2', '2', '3', '4', '4', '4', '5', '5']
# 利用 defaultdict
count = defaultdict(int)
for i in num:
count[i] += 1
print(dict(count))
# 第二种
print(Counter(num))
# 第三种
c = dict.fromkeys(num, 0)
for i in num:
c[i] += 1
print(c)
# 第四种
count = dict()
for i in num:
count.setdefault(i, 0)
count[i] += 1
print(count)