Standard library · 8 / 17 Exercise Medium

Most common words

Objective

Create a Python program that shows the three words that are repeated the most in a text using Counter.

Instructions

  • Import Counter from the collections module.
  • Read a line of text with words separated by spaces, without punctuation marks, and convert it to lower case.
  • Count the words with Counter and get the three most common ones with most_common(3).
  • Show one line per word with the format word: times, from most to least frequent. If there is a tie, the one that appeared first in the text goes first.
  • If there are fewer than three distinct words, show only the ones there are.
Input
el sol y el mar y el cielo
Output
el: 3
y: 2
sol: 1

Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.

Start exercise