Python实现wordcount
import string
def wordcount(s):
# 去除标点符号的函数
translator = str.maketrans('', '', string.punctuation)
# 将字符串转换成小写,并去除标点符号
s = s.translate(translator).lower()
# 按空格和换行符分割字符串,得到单词列表
words = s.split()
# 使用字典统计单词出现的次数
word_count = {}
for word in words:
if word in word_count:
word_count[word] += 1
else:
word_count[word] = 1
return 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.
"""
output = wordcount(text)
print(output)
任务二:debug的全流程
大概熟悉debug的整个流程。