任务一 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’![在这里插入图片描述](https://i-blog.csdnimg.cn/direct/3234739f1d6c47b896a1c288a3224710.png)
2.连接开发机:
连接成功
粘贴函数到代码里
输出结果: