在列表列表中的测试中,索引总是超出范围



每当我试图运行此函数来测试列表列表上的特定值时,它都会从索引中返回:

#this is the list of list running through the functions:
[['District', 'Acton Town', 'Ealing Common', 2], ['Piccadilly', 'Acton Town', 'Ealing Common', 2], ['Piccadilly', 'Ealing Common', 'North Ealing', 2], ['Piccadilly', 'North Ealing', 'Park Royal', 2], ['Piccadilly', 'Park Royal', 'Alperton', 2], ['Piccadilly', 'Alperton', 'Sudbury Town', 3], ['Piccadilly', 'Sudbury Town', 'Sudbury Hill', 2], ['Piccadilly', 'Sudbury Hill', 'South Harrow', 3], ['Piccadilly', 'South Harrow', 'Rayners Lane', 5], ['Metropolitan', 'Rayners Lane', 'West Harrow', 3], ['Metropolitan', 'West Harrow', 'Harrow-on-the-Hill', 2], ['Metropolitan', 'Moor Park', 'Harrow-on-the-Hill', 14], ['Metropolitan', 'Rickmansworth', 'Moor Park', 5], ['Metropolitan', 'Chorleywood', 'Rickmansworth', 4], ['Metropolitan', 'Chalfont & Latimer', 'Chorleywood', 4], ['Metropolitan', 'Amersham', 'Chalfont & Latimer', 4]]
def reverse_if_needed(self):
"""
Reverse when needed
"""
final = []
full_info = self.eliminate_repetition()
for i in range(len(full_info)):
if full_info[i][1] != full_info[i-1][2]:
final.append(self.reverse(full_info[i]))
return final
def eliminate_repetition(self):
full_info = self.get_full_route_detail()
new_full_info = []
for x in range(len(full_info)):
if full_info[x][1] != full_info[x - 1][1] and full_info[x][2] != full_info[x - 1][2]:
new_full_info.append(full_info[x])
return new_full_info

函数self.reverse(full_info[i])的作用是什么?我用full_info[i]替换了这个函数,没有出现任何错误。

相关内容

  • 没有找到相关文章

最新更新