任务概览
任务类型 | 任务内容 |
---|---|
闯关任务 | Python实现wordcount |
闯关任务 | Vscode连接InternStudio debug笔记 |
一、Python实现wordcount
def wordcount(text):
# 将字符串转为小写,去除标点符号,并分割成单词列表
import re
words = re.findall(r'\b\w+\b', text.lower())
# 统计每个单词出现的次数
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!"""
# 调用wordcount函数并打印结果
result = wordcount(text)
print(result)
二、Vscode连接InternStudio debug
通过SSH连接InternStudio的开发机。
为开发机安装Python插件,用于debug。(只需要安装合适版本Python即可,根据我个人经验,安装较为老一点的版会更好,当然这个平台安装最新的没有出现什么问题)
接下来就可以打断点了,但是打断点前确保代码没有问题,可以如下图运行代码:
能顺利运行,接下来打一个断点,如图:
debug效果如图: