Start free

Intermediate · Sets · 141 of 264

Different words

How many different words are in a line? Ignore capital letters.

Input: one line of words. Output: the number of different words.

Examples

Input
the cat and The hat
Output
4
Input
a a a
Output
1
Input
one two three
Output
3

One more test checks other inputs when you press Check.

Stuck? The idea behind sets

A set holds each value once, in no particular order: set(list) drops repeats at once.

Checking whether a value is in a set is fast. & keeps what two sets share, | joins them, - keeps what is only in the first.

a = set(input().split())
b = set(input().split())
print(sorted(a & b))

Watch for: A set has no order: sort it (sorted()) before printing, or the order may change.

All the sets exercises
Your code
Opening the code editor…
Python 3.14 in your browser
Output
Run shows what your program prints. Check tests it on every example and the hidden tests.

More sets exercises