Most common word
Most common word
Find the favourite word of a piece of text.
Work in three stages. Clean: remove the punctuation with .replace() and make everything lowercase with .lower(). Count: .split() the text into words and count them in a dictionary with counts.get(word, 0) + 1. Choose: walk through the words in their original order and switch to a word only when its count is strictly bigger, so that a tie goes to the earlier word.
最も頻出する単語
テキストの中で最も好まれる(出現回数の多い)単語を見つけてください。
3つの工程で行います。クリーニング: .replace() で句読点を削除し、.lower() で全てを小文字にします。カウント: .split() でテキストを単語に分割し、counts.get(word, 0) + 1 で辞書内に個々の単語の数を数えます。選択: 単語を元の順序で巡回し、出現数がより大きくなった場合にのみ更新します。同点の場合は最初の単語が選ばれます。
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.
Click Run to see the output here. · 実行ボタンをクリックして出力を確認してください。