Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
doble for solution in Clear category for The Most Frequent by EdinsonUwU
def most_frequent(data: list) -> str:
set_of_counters = {}
for i in data:
if i not in set_of_counters:
set_of_counters[i] = 1
else:
set_of_counters[i] = set_of_counters[i] + 1
most_frequent_value = None
most_frequent_value_counter = 0
for i in set_of_counters.items():
if (i[1]>most_frequent_value_counter):
most_frequent_value = i[0]
most_frequent_value_counter = i[1]
return most_frequent_value
if __name__ == "__main__":
# These "asserts" using only for self-checking and not necessary for auto-testing
print("Example:")
print(most_frequent(["a", "b", "c", "a", "b", "a"]))
assert most_frequent(["a", "b", "c", "a", "b", "a"]) == "a"
assert most_frequent(["a", "a", "bi", "bi", "bi"]) == "bi"
print("Done")
March 27, 2022
Comments: