#C13834. Frequency Count and Sorted Dictionary
Frequency Count and Sorted Dictionary
Frequency Count and Sorted Dictionary
Given a list of integers, your task is to compute the frequency for each unique integer and output a dictionary with the integers as keys and their frequency counts as values. The dictionary must be sorted in descending order by frequency.
Specifically, if two integers have the same frequency, their relative order in the output does not matter.
The input is provided via standard input. Your solution should be efficient in terms of time and space.
Note: The output format should exactly match the Python dictionary representation. For example, an empty list should produce {}, and a list containing a single integer 1 should produce {1: 1}.
The expected behavior with some examples:
- Input:
6
followed by1 2 2 3 3 3
produces output:{3: 3, 2: 2, 1: 1}
- Input:
5
followed by-1 -1 -2 -2 -2
produces output:{-2: 3, -1: 2}
inputFormat
The input is read from standard input and consists of two parts:
- The first line contains a single integer n which represents the number of elements.
- If n > 0, the second line contains n space-separated integers.
If n is zero, there will be no second line.
outputFormat
Output the frequency dictionary in the format of a Python dictionary. This means the output should be enclosed in curly braces and keys and values should be separated by a colon and a space. The dictionary should be ordered in descending order by the frequency counts.
## sample0
{}