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 krzysztof.gonda
def most_frequent(data):
data.sort()
maxl = data[0]
maxc = 0
count = 1
for x in range(1,len(data)):
if (data[x]==data[x-1]):
count += 1
else:
if(count>maxc):
maxc = count
maxl = data[x-1]
count = 1
if(count>maxc):
maxc = count
maxl = data[len(data)-1]
return maxl
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')
Nov. 18, 2017