1Python实现wordcount
import re
from collections import defaultdict
def wordcount(text):
# 定义要移除的标点符号
punctuations = ".,!?;:"
# 去掉标点符号
for char in punctuations:
text = text.replace(char, "")
# 将所有单词转换成小写
text = text.lower()
# 分割字符串成单词
words = text.split()
# 统计每个单词出现的次数
word_count = defaultdict(int)
for word in words:
word_count[word] += 1
return dict(word_count)
# 示例输入
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.
"""
# 调用函数并打印结果
result = wordcount(text)
print(result)
2.VScode远程连接实现debug
找到我们的python文件并在VScode中打开
直接点击运行和调试即可进行debug