def mode(given_list):
highest_list = []
highest = 0
index = 0
for x in range(0, len(given_list)):
occurrences = given_list.count(given_list[x])
if occurrences > highest:
highest = occurrences
highest_list[0] = given_list[x]
elif occurrences == highest:
highest_list.append(given_list[x])
The code is meant to work out the mode of a given list. I do not understand where I am going wrong.
Exact Error I am receiving.
line 30, in mode
highest_list[0] = given_list[x]
IndexError: list assignment index out of range