任务一
请实现一个wordcount函数,统计英文字符串中每个单词出现的次数。返回一个字典,key为单词,value为对应单词出现的次数。
def wordcount(text):
# 将文本转换为小写,以避免大小写影响单词计数
text = text.lower()
# 使用正则表达式替换标点符号为空格
import re
text = re.sub(r'[^\w\s]', ' ', text)
# 分割文本为单词列表
words = text.split()
# 创建字典来存储每个单词的计数
word_count = {}
# 遍历单词列表并计数
for word in words:
if word in word_count:
word_count[word] += 1
else:
word_count[word] = 1
return word_count
# 示例使用
text = """Hello world!
This is an example.
Word count is fun.
Is it fun to count words?
Yes, it is fun!"""
count = wordcount(text)
print(count)
任务二
请使用本地vscode连接远程开发机,将上面你写的wordcount函数在开发机上进行debug,体验debug的全流程,并完成一份debug笔记(需要截图)。
一开始链接不上开飞机
报错:Could not establish connection to “project”
左侧栏打开Extentions,找到已经安装好的Remote -SSH,右键点击,选择“Extension Settings”
在Config File中输入你自己的config文件路径
然后重新尝试连接,发现成功了
接下来就可以进行debug测试了