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.
"""defwordcount(text):# 将所有单词转换为小写
text = text.lower()# 去除标点符号只保留字母和空格import re
text = re.sub(r'[^\w\s]','',text)# 拆分字符串为单词列表
words = text.split()# 创建一个空字典用于存储单词出现次数
word_count_dict ={}# 遍历单词列表,统计每个单词出现的次数for word in words:if word in word_count_dict:
word_count_dict[word]+=1else:
word_count_dict[word]=1return word_count_dict
print(wordcount(text))