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.
가장 흔한 단어
텍스트의 가장 좋아하는 단어를 찾습니다.
세 단계로 수행합니다. 정제: .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. · 출력을 보려면 '실행'을 클릭하세요.