Dictionaries · 7 / 15 Exercise Easy

Count words

Objective

Create a Python program that counts how many times each word of a text appears using a dictionary.

Instructions

  • Read a line of text with words separated by spaces, without punctuation marks.
  • Convert the text to lower case so that Sun and sun count as the same word.
  • Store in a dictionary each word and the number of times it appears.
  • Show one line per word, sorted alphabetically, with the format word: times.
Input
el sol y la luna y el mar
Output
el: 2
la: 1
luna: 1
mar: 1
sol: 1
y: 2

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

Start exercise