Counter 计数字典
1个月前 • 166次点击 • 来自 Python
from collections import Counter
# 计数
cnt = Counter()
for word in ['red','red','blue','green']
cnt[word] + = 1
print(cnt)
# Counter({'blue':1,'red':2,'green':1})
标签
1个月前 • 166次点击 • 来自 Python
from collections import Counter
# 计数
cnt = Counter()
for word in ['red','red','blue','green']
cnt[word] + = 1
print(cnt)
# Counter({'blue':1,'red':2,'green':1})