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 szneqz
def most_frequent(data):
"""
determines the most frequently occurring string in the sequence.
"""
newData = []
state = False
intData = []
i = 0
j = 0
datindex = 0
for strings in data:
state = True
for strings2 in newData:
if strings2 == strings:
state = False
if state == True:
newData.append(strings)
for strings2 in newData:
i = 0
for strings in data:
if strings == strings2:
i = i + 1
intData.append(i)
i = 0
for ints in intData:
if ints > j:
j = ints
datindex = i
i = i + 1
return newData[datindex]
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. 22, 2018