利用Counter的字典
from collections import Counter
total_counts = Counter()
sentence='hello world'
for word in sentence.split(" "):
total_counts[word] += 1
print(total_counts)
输出
Counter({'hello': 1, 'world': 1})
利用Counter的字典
from collections import Counter
total_counts = Counter()
sentence='hello world'
for word in sentence.split(" "):
total_counts[word] += 1
print(total_counts)
输出
Counter({'hello': 1, 'world': 1})