Most common word
此页面需较新浏览器(支持 SharedArrayBuffer)。请升级 Chrome、Edge、Firefox 或 Safari 至最新版本。
此任务基于您尚未完成的课程。请先完成以下课程:
Python 基础 · Dictionaries (records) →
出现最多的单词
找出一段文字里最常用的单词。
分三步来做。清理:用 .replace() 去掉标点,用 .lower() 全部变成小写。计数:用 .split() 把文字分成单词,再用字典和 counts.get(word, 0) + 1 计数。选择:按原来的顺序遍历单词,只有次数严格更大时才换成这个单词,这样次数相同时就会留下先出现的单词。
难度 5/5 · 今日首次完成可获 400 金币及少量额外奖励
Write most_common_word(text) that returns the word used most often, ignoring upper and lower case and the punctuation marks .,!?. If two words tie, return the one that appears first.
点击“运行”查看此处输出。