Python task

def wordcount(text):
    # 将文本分割成单词列表,并转换为小写
    words = text.lower().split()
    
    # 初始化一个空字典用于存储单词计数
    word_counts = {}
    
    # 遍历单词列表中的每个单词
    for word in words:
        # 如果单词在字典中,则计数加1,否则将单词加入字典并设为1
        if word in word_counts:
            word_counts[word] += 1
        else:
            word_counts[word] = 1
            
    return word_counts

# 测试函数
text = """Hello world!  
This is an example.  
Word count is fun.  
Is it fun to count words?  
Yes, it is fun!"""

word_counts = wordcount(text)
print(word_counts)

ssh链接
在这里插入图片描述

安装插件


运行
在这里插入图片描述

在这里插入图片描述
程序运行结果
在这里插入图片描述

相关推荐

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-12 04:44:06       67 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-12 04:44:06       72 阅读
  3. 在Django里面运行非项目文件

    2024-07-12 04:44:06       58 阅读
  4. Python语言-面向对象

    2024-07-12 04:44:06       69 阅读

热门阅读

  1. 力扣2434.使用机器人打印字典序最小的字符串

    2024-07-12 04:44:06       28 阅读
  2. IT专业入门,高考假期预习指南

    2024-07-12 04:44:06       19 阅读
  3. 简谈设计模式之设计原则

    2024-07-12 04:44:06       28 阅读
  4. Spring

    2024-07-12 04:44:06       23 阅读
  5. react hooks antd 父组件取子组件form表单的值

    2024-07-12 04:44:06       22 阅读
  6. 数据分析的汇报与观点表达

    2024-07-12 04:44:06       27 阅读
  7. GPT-5 对人工智能领域的深远影响

    2024-07-12 04:44:06       22 阅读