Count how many different values appear in a list.
Input
Line 1: an integer n.
Line 2: n integers.
Output
The number of distinct values.
Count how many different values appear in a list.
Line 1: an integer n.
Line 2: n integers.
The number of distinct values.
Example 1
5 1 2 2 3 3
3
Distinct values are 1, 2, 3 — three of them.
Example 2
4 7 7 7 7
1
Only one distinct value.
Example 3
3 1 2 3
3
All different.
A set keeps only one copy of each value.
Insert every number into a set and report its size.
Insert all values into a set; the answer is the set size.
import sys
d = list(map(int, sys.stdin.read().split()))
n = d[0]
print(len(set(d[1:1 + n])))
Tell us what needs to change, who it affects and any important deadline. We will review the context and reply with useful next questions.