Two Maximum Frequencies 1 X13869


Statement
 

pdf   zip

html

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

Input is received as argument of the function: it is an arbitrary list of strings. The result returned by the function must be a pair formed by two lists. The first list contains the words that appear with maximum frequency in the input, sorted according to their standard Python ordering. The second list contains the words that appear with second maximum frequency in the input, sorted likewise. Think carefully whether each of the output lists can be empty.

Sample session
>>> print(max2freq([ 'four', 'three', 'four', 'threeaswell',
... 'alsofour', 'onlyonce', 'alsofour', 'alsothree', 'alsothree',
... 'four', 'alsofour', 'four', 'alsofour', 'three', 'threeaswell',
... 'threeaswell', 'three', 'alsothree', 'alsoonlyonce' ]))
(['alsofour', 'four'], ['alsothree', 'three', 'threeaswell'])
>>> print(max2freq(['twice', 'twice', 'once', 'thrice',
... 'thrice', 'retwice', 'retwice', 'thrice' ]))
(['thrice'], ['retwice', 'twice'])
>>>
Information
Author
ProAl
Language
English
Official solutions
Python
User solutions
Python