任务1:请实现一个wordcount函数,统计英文字符串中每个单词出现的次数。返回一个字典,key为单词,value为对应单词出现的次数。
import string
def count_words(text):
store = {}
translator = str.maketrans('', '', string.punctuation) #创建字符映射表
#maketrans(x,y,z) x:要替换的字符 y:替换后的字符 z:要删除的字符
cleaned_text = text.translate(translator) #根据映射表进行删除
words = cleaned_text.lower().split() #将所有字母转换为小写并按照空格分
for word in words:
if word in store:
store[word] += 1
else:
store[word] = 1
return store
text = """Hello world! #''' '''可以多行行输入
This is an example.
Word count is fun.
Is it fun to count words?
Yes, it is fun!"""
store = count_words(text)
print(store)
任务2:请使用本地vscode连接远程开发机,将上面你写的wordcount函数在开发机上进行debug,体验debug的全流程,并完成一份debug笔记(需要截图)
1、vscode通过ssh链接到远程服务器后,可以直接将本地的扩展选择安装到远程服务器
2、在本地vscode debug