Task 1:word_count实现
代码:
def count_words(paragraph: str):
results = {}
paragraph = paragraph.strip()
paragraph = re.sub(r"[^A-Za-z ]", "", paragraph).lower()
words = paragraph.split(" ")
for word in words:
if word != "":
results[word] = results.get(word, 0) + 1
return results
运行结果:
{'hello': 1, 'world': 1, 'this': 1, 'is': 4, 'an': 1, 'example': 1, 'word': 1, 'count': 2, 'fun': 3, 'it': 2, 'to': 1, 'words': 1, 'yes': 1}
Task 2:调试
- 单步进入待调试函数
- 控制台调试,查看变量值
下一步,打印去标点、转小写后的文本
- 继续:完成调试
输出结果