目录
任务一:使用Python实现简易WordCount函数
先把标点符号替换为空,把所有字母变成小写
然后遍历所有单词,如果出现过就次数+1,没出现过,就设定次数为1
def wordcount(text):
cleaned_text = text.replace(",","").replace(".","").replace("?","").replace("!","").replace("\n","").lower()
words = cleaned_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!"""
print(wordcount(text))
任务二:Vscode远程连接开发机进行python debug
debug单个python文件
eg: 第一个词,hello,因为没有出现过,所以记一个次数
使用命令行debug
配置文件生成
课程任务跟练
debug单个python文件
使用命令行发起python debug
配置文件生成
发起debug server的命令
python -m debugpy --listen 5678 --wait-for-client ./myscript.py
用到第三方包debugpy,listen是监听端口,wait-for-client等待连接上才发起debug流程,./myscript.py是debug文件
安装debugpy包
成功开启debug
这种方式的好处是可以直接在命令行添加参数