#C13485. Count Integer Occurrences
Count Integer Occurrences
Count Integer Occurrences
Given a list of integers, your task is to count the number of times each integer appears and return the result as a dictionary. The keys of the dictionary are the integers, and the corresponding values are the counts of those integers.
You should read the input from STDIN and write the output to STDOUT. The output must be in the form of a Python-style dictionary with keys in increasing order. For example, if the input list is [1, 2, 2, 3], the output should be {1: 1, 2: 2, 3: 1}
.
Note that if the list is empty, you must output an empty dictionary: {}
.
In mathematical form, if the input list is (A = [a_1, a_2, \ldots, a_n]), then for each unique integer (k) in (A), compute its frequency (f(k)) and output the dictionary: (
{ k: f(k) \mid k \in A }).
inputFormat
Input is given in two lines. The first line contains a single integer (n) which represents the number of integers. The second line contains (n) space-separated integers.
outputFormat
Output a dictionary in the Python format with keys sorted in increasing order. Each key is an integer from the input, and its value is the number of times it appears. Even if the dictionary is empty, output {}.## sample
5
1 2 3 4 5
{1: 1, 2: 1, 3: 1, 4: 1, 5: 1}