Two Maximum Frequencies 2 X53567


Statement
 

pdf   zip

html

Write a function max2freq that receives as argument a list of integer values, and finds in it both the values that appear with maximum frequency and the values that appear with second maximum frequency.

Input is received as argument of the function: it is an arbitrary list of integer values. The result returned by the function must be a pair formed by two lists. The first list contains the values that appear with maximum frequency in the input, ordered increasingly. The second list contains the values that appear with second maximum frequency in the input, also ordered increasingly. Think carefully whether each of the output lists can be empty.

Sample session
>>> print(max2freq([ 40, 30, 40, 32, 41, 10, 41, 31, 31,
... 40, 41, 40, 41, 30, 32, 32, 30, 31, 11 ]))
([40, 41], [30, 31, 32])
>>> max2freq([ 20, 20, 10, 30, 30, 21, 21, 30 ])
([30], [20, 21])
Information
Author
ProAl
Language
English
Official solutions
Python
User solutions
Python