Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Creative category for The Most Frequent by zimnytam
def most_frequent(data):
"""
determines the most frequently occurring string in the sequence.
"""
# your code here
total = 0
lower = data
most = lower[0]
for i in lower:
if lower.count(i) > total:
most = i
total = lower.count(i)
elif lower.count(i) == total:
if i < most:
most = i
total = lower.count(i)
return most
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')
Oct. 21, 2017
Comments: