Command Palette

Search for a command to run...

Hectal
Phase 4: Lists, Tuples, Dictionaries and Sets
Python · Exercise 4 of 6 PreviousNext
Beginner

Count the words

Start from text = "to be or not to be". Use text.split() to get the words.

Build a dictionary counts that says how many times each word appears, with a loop. Make a set unique of the different words.

Print Unique words: 4 using unique, and then to appears 2 times using counts.

What Check tests

  1. counts is correct
  2. unique holds the 4 different words
  3. The program prints Unique words: 4
  4. The program prints to appears 2 times

Stuck? One hint at a time

The solution unlocks after your first Check. Try first: that is where the learning happens.

main.py
Sign in to run your code.

Output

Press Run to see what your program prints.