1 闯关任务
Python实现wordcount
import re
def wordcount(text):
# 使用正则表达式替换标点符号为空格
text = re.sub(r'[.,;!?]', ' ', text)
# 将文本分割成单词列表并转换为小写
words = text.lower().split()
# 创建一个字典来存储单词计数
word_counts = {}
# 遍历单词列表,更新字典中的计数
for word in words:
if word in word_counts:
word_counts[word] += 1
else:
word_counts[word] = 1
return word_counts
# 示例用法
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.
"""
print(wordcount(text))
2 闯关任务
Vscode连接InternStudio debug笔记
注意:vscode安装了python插件,如果没有生效,重启vscode
g笔记
注意:vscode安装了python插件,如果没有生效,重启vscode