统计单词数量:collections.Counter
模块作用
collections.Counter 用来快速统计每个内容出现了多少次。
from collections import Counter
words = input().split()
c = Counter(words)
print(c["cat"])
小练习
输入内容是:cat dog cat,程序会输出什么?
提交要求: 只提交最终输出结果,不要添加多余的说明或引号。
collections.Counter 用来快速统计每个内容出现了多少次。
from collections import Counter
words = input().split()
c = Counter(words)
print(c["cat"])
输入内容是:cat dog cat,程序会输出什么?
提交要求: 只提交最终输出结果,不要添加多余的说明或引号。
全部评论