livepython.net

124. Python Program to Count Unique Words in a Sentence

EasySets

Overview

A set keeps each word once, so its length is the number of different words.

Problem Statement

Read one line of words separated by spaces. Print how many words it has, and how many different words. Words that differ only in capital letters count as the same word. For example, for the cat and the dog and the bird:

Words: 8
Unique words: 5

Use input() with no prompt text: the tests type the input for you, and a prompt would end up in your output.

Input

One line of words. Example:

the cat and the dog and the bird

Output

The output for that example:

Words: 8
Unique words: 5

The tests try 4 different inputs.

Learn this firstChapter 14 · Python Sets: Unique Items, add(), remove() and in
solution.py
# write your code here

EXPECTED OUTPUT

1Words: 8
2Unique words: 5

YOUR OUTPUT

Press Run to see your output here. Lines are compared with the expected output.