Python task
1.Python实现Wordcount
import re
def wordcount(text):
# 去除标点符号并转换为小写
translator = str.maketrans('', '', string.punctuation)
text = text.translate(translator).lower()
# 按空格分割成单词列表
words = text.split()
# 统计每个单词出现的次数
word_freq = {}
for word in words:
if word in word_freq:
word_freq[word] += 1
else:
word_freq[word] = 1
return word_freq
# 测试示例
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