【发布时间】:2016-01-22 22:43:14
【问题描述】:
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])
代码旨在计算给定列表的模式。我不明白我哪里出错了。
我收到的确切错误。
line 30, in mode
highest_list[0] = given_list[x]
IndexError: list assignment index out of range
【问题讨论】:
标签: python list python-3.x indexof