酷代码 AI
菜单
服务商
DeepSeek字节豆包讯飞星火
更多选项

Python 实现:输入英文文本统计各单词(不区分大小写)出现次数

以下是使用 Python 实现的代码: ```python def count_words(text): text = text.lower() # 将所有字母转换为小写,以便不区分大小写 words = text.split() # 按空格分割单词 word_count = {} for word in words: if word in word_count: word_count[word] += 1 else: word_count[word] = 1 result = "" for word, count in word_count.items(): result += word + str(count) return result text = input("请输入英文文本(不包含标点符号):") print(count_words(text)) ``` ######[AI写代码神器 | 151点数解答 | 2024-10-17 11:38:00]

相关提问
本站限时免费提问中
实用工具查看更多
Linux在线手册 [开发类]
Jquery在线手册 [开发类]
今日油价 [生活类]
图片互转base64 [开发类]
时间转换器 [开发类]