统计单词数量:collections.Counter

👁️ 1 人浏览 💬 0 人评论 ❤️ 添加收藏

模块作用

collections.Counter 用来快速统计每个内容出现了多少次。

from collections import Counter

words = input().split()
c = Counter(words)
print(c["cat"])

小练习

输入内容是:cat dog cat,程序会输出什么?

提交要求: 只提交最终输出结果,不要添加多余的说明或引号。

提交你的答案
请登录后提交答案。
去登录
代码编辑器
Ctrl + Enter 运行
输入:
输出:

                        
👩‍🏫
AI
💬 题目评论

全部评论