Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for The Most Frequent by bart.t
def most_frequent(data):
"""
determines the most frequently occurring string in the sequence.
"""
# your code here
count = {}
max_count = 0
max_item = 0
for w in data:
if w not in count:
count[w] = 1
else:
count[w]+=1
if count[w]>max_count:
max_count = count[w]
max_item = w
return max_item
if __name__ == '__main__':
#These "asserts" using only for self-checking and not necessary for auto-testing
assert most_frequent([
'a', 'b', 'c',
'a', 'b',
'a'
]) == 'a'
assert most_frequent(['a', 'a', 'bi', 'bi', 'bi']) == 'bi'
print('Done')
Jan. 24, 2018