Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for The Most Frequent by vlad.bezden
"""
The Most Frequent.
You have a sequence of strings, and you’d like to determine
the most frequently occurring string in the sequence.
Input: a list of strings.
Output: a string.
"""
from collections import Counter
def most_frequent(data: list) -> str:
return Counter(data).most_common(1)[0][0]
if __name__ == '__main__':
assert most_frequent([
'a', 'b', 'c',
'a', 'b',
'a'
]) == 'a'
assert most_frequent(['a', 'a', 'bi', 'bi', 'bi']) == 'bi'
Oct. 1, 2018