任务类型 | 任务内容 |
闯关任务 | python实现wordcount |
闯关任务 | Vscode连接InternStudio debug笔记 |
1.python实现wordcount
请实现一个wordcount函数,统计英文字符串中每个单词出现的次数。返回一个字典,key为单词,value为对应单词出现的次数
text = """
Got this panda plush toy for my daughter's birthday, who loves it and takes it everywhere. It's soft and super cute, and its face has a friendly look. It's a bit small for what I paid though. I think there might be other options that are bigger for the same price. It arrived a day earlier than expected,
so I got to play with it myself before I gave it to her.
"""
def wordcount(text):
text = text.replace(",", "").replace(".", "").replace("\n", "")
text = text.lower()
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
print(wordcount(text))
运行结果:
2.Vscode连接InternStudio debug笔记
使用本地vscode连接远程开发机,新建debug_test.py,并安装python扩展,打上断点
用命令行发起debug
配置调试的基础设置
-
点击VSCode侧边栏的“Run and Debug”(运行和调试),单击"create a lauch.json file"
-
之后,debugger的选择为python debuger
-
debug config时选择remote attach
-
Remote Debugging的IP和port分别选择默认的localhost和5678,直接回车即可。
最后出现debug选项的界面为:
在服务器终端输入以下命令开始调试:
python -m debugpy --listen 5678 --wait-for-client ./debug_test.py
先在终端中发起debug server,然后再去vscode debug页面单击一下绿色箭头开启debug。
标签:count,word,Python,text,wordcount,python,debug,Camp3,浦语 From: https://blog.csdn.net/weixin_46610879/article/details/141355835