#C13327. Counting Element Frequencies
Counting Element Frequencies
Counting Element Frequencies
You are given a list of integers. Your task is to count the frequency of each unique element in the list and output the result as a dictionary. The keys of the dictionary are the unique integers, and the corresponding values are their counts.
In other words, given an input list \( L = [a_1, a_2, \dots, a_n] \), you need to compute a dictionary \( D \) such that for every element \( x \) in \( L \), the entry \( D[x] \) equals the number of times \( x \) appears in \( L \). The output should be printed in the following format:
For a non-empty dictionary, print the dictionary in the form
{key1: value1, key2: value2, ...} with the keys sorted in increasing order. For an empty list, simply print {}.
For example, if the input is "1 2 2 3 3 3 4", then the output should be "{1: 1, 2: 2, 3: 3, 4: 1}".
inputFormat
The input is given via standard input. It consists of a single line containing zero or more space-separated integers. If the input line is empty, it corresponds to an empty list.
Examples:
- "1 2 3 4"
- "1 2 2 3 3 3 4"
- "" (an empty line for an empty list)
outputFormat
The output should be printed to standard output in one line, which is a dictionary with unique integers as keys and their counts as values. The dictionary should be printed in the format:
{key1: value1, key2: value2, ...}
with the keys sorted in increasing order. For an empty list, output {}.
## sample1
{1: 1}