闯关任务1:
请实现一个wordcount函数,统计英文字符串中每个单词出现的次数。返回一个字典,key为单词,value为对应单词出现的次数。
代码如下:
def wordcount(text):
import re
words = re.findall(r'\b\w+\b', text.lower())
word_count = {}
for word in words:
if word in word_count:
word_count[word] += 1
else:
word_count[word] = 1
return word_count
# 示例输入
text = """Hello world!
This is an example.
Word count is fun.
Is it fun to count words?
Yes, it is fun!"""
result = wordcount(text)
print(result)
闯关任务2:
Vscode连接InternStudio debug笔记
debug过程(左边红点为断点):
运行结果: