Read a list of whole numbers and print how many different values it contains.
What to build
A program that lets a set find the repeats.
Requirements
- Read the numbers.
- Print how many different values there are.
Input
The first line has n (1 to 1000). The second line has n whole numbers separated by spaces.
Output
The number of different values.
Constraints
n is from 1 to 1000.
Example
Input:
5
72 85 72 90 85
Output:
3
Why it works
A set keeps one copy of each value, so its length is the number of different values.
Examples
Example 1 · Input
5 72 85 72 90 85
Expected output
3
Example 2 · Input
3 1 2 3
Expected output
3
Prompts inside input() are ignored when checking, so input("n: ") is fine.
Hints
Hint 1
set() keeps each value only once.
Hint 2
len() of a set counts its values.
Solution
Show one correct solution (try it yourself first)
n = int(input()) nums = input().split() print(len(set(nums)))