大模型笔记-书生训练营第三期闯关指南 1.3 python
- 1 闯关任务
- 2 闯关任务
1 闯关任务
Python实现wordcount
import redef 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] += 1else:word_counts[word] = 1return 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