单词计数

课程:Python · 编程练习

Python编程练习 - 单词计数

练习内容

# 统计文本中单词出现的频率\ndef count_words(text):\n # 转换为小写并分割单词\n words = text.lower().split()\n word_count = {}\n\n for word in words:\n # 移除标点符号\n cleaned_word = ''.join(c for c in w