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. """
text = """Hello world! This is an example. Word count is fun. Is it fun to count words? Yes, it is fun!"""
text1 = """ 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. """
import re
defwordcount(text): # 将文本转换为小写 text = text.lower() # 使用正则表达式移除标点符号 text = re.sub(r'[^\w\s]', '', text) # 分割文本为单词列表 words = text.split() # 创建一个字典来存储单词计数 word_count = {} # 遍历单词列表,计数 for word in words: if word in word_count: word_count[word] += 1 else: word_count[word] = 1 return word_count