输入:
from collections import Counter
counter = Counter()
for word in ['我', '是', '中国', '人', '我', '爱', '中国']:
counter[word] += 1
print(counter)
输出:
Counter({'我': 2, '中国': 2, '是': 1, '人': 1, '爱': 1})
输入:
from collections import Counter
counter = Counter()
for word in ['我', '是', '中国', '人', '我', '爱', '中国']:
counter[word] += 1
print(counter)
输出:
Counter({'我': 2, '中国': 2, '是': 1, '人': 1, '爱': 1})