Python task

任务一 Python实现wordcount

请实现一个wordcount函数,统计英文字符串中每个单词出现的次数。返回一个字典,key为单词,value为对应单词出现的次数。

文本:

Alice: Hi Bob, how are you today?
Bob: Hi Alice, I’m good, thanks! How about you?
Alice: I’m doing well, thanks for asking. Have you finished the report for our project?
Bob: Not yet, I’ve been working on it. There’s a lot of data to analyze.
Alice: I see. Do you need any help with it?
Bob: That would be great. Can you help me with the data visualization part?
Alice: Sure! I can create some charts and graphs. Do you have the data ready?
Bob: Yes, I’ve compiled the data from the surveys. It’s all in this Excel file.
Alice: Perfect. Send it to me and I’ll start working on it right away.
Bob: Thanks, Alice. I’ll send it over now.
Alice: No problem, Bob. We make a great team!
Bob: Indeed we do. By the way, are you free this weekend? We could work on the project together.
Alice: I think so. Let me check my schedule and get back to you.
Bob: Sounds good. Looking forward to it!

wordcount 函数实现

def wordcount(text):
    import re
    # 使用正则表达式去除标点符号并将文本转换为小写
    words = re.findall(r'\b\w+\b', text.lower())
    word_freq = {}
    for word in words:
        if word in word_freq:
            word_freq[word] += 1
        else:
            word_freq[word] = 1
    return word_freq

# 测试 wordcount 函数
text = """
Alice: Hi Bob, how are you today?
Bob: Hi Alice, I’m good, thanks! How about you?
Alice: I’m doing well, thanks for asking. Have you finished the report for our project?
Bob: Not yet, I’ve been working on it. There’s a lot of data to analyze.
Alice: I see. Do you need any help with it?
Bob: That would be great. Can you help me with the data visualization part?
Alice: Sure! I can create some charts and graphs. Do you have the data ready?
Bob: Yes, I’ve compiled the data from the surveys. It’s all in this Excel file.
Alice: Perfect. Send it to me and I’ll start working on it right away.
Bob: Thanks, Alice. I’ll send it over now.
Alice: No problem, Bob. We make a great team!
Bob: Indeed we do. By the way, are you free this weekend? We could work on the project together.
Alice: I think so. Let me check my schedule and get back to you.
Bob: Sounds good. Looking forward to it!
"""

value = wordcount(text)
print(value)

任务二

请使用本地vscode连接远程开发机,将上面你写的wordcount函数在开发机上进行debug,体验debug的全流程,并完成一份debug笔记(需要截图)。

笔记:

先安装remote-ssh’在这里插入图片描述

2.连接开发机:

在这里插入图片描述

连接成功

在这里插入图片描述

粘贴函数到代码里

输出结果:
在这里插入图片描述

  • 10
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值