Python索引器:列表索引超出范围(扫描算法)
我的代码出现问题,显示错误:Python索引器:列表索引超出范围(扫描算法),python,algorithm,list,loops,while-loop,Python,Algorithm,List,Loops,While Loop,我的代码出现问题,显示错误: File "C:\Users\gileu\Google Drive\FIME\Temas Selectos de Optimización\Heuristica de Barridos\Barridos.py", line 85, in <module> elif(datos[j][2] <= ca): IndexError: list index out of range 问题似乎出在代码的这一部分: while(ca&
File "C:\Users\gileu\Google Drive\FIME\Temas Selectos de Optimización\Heuristica de Barridos\Barridos.py", line 85, in <module>
elif(datos[j][2] <= ca):
IndexError: list index out of range
问题似乎出在代码的这一部分:
while(ca>=0):
if(ca == 0):
i = i + 1
break
elif(datos[j][2] <= ca):
grupos[i].append(ang.index(angO[0]))
angO.remove(angO[0])
j = j + 1
elif(datos[j][2] > ca):
i = i + 1
break
while(ca>=0):
如果(ca==0):
i=i+1
打破
elif(datos[j][2]ca):
i=i+1
打破
您已经初始化了ca=c,即80。在这个while循环中,您永远不会减少
ca
,因此这本质上是一个无限循环。虽然值len(datos)
是有限的,但是如果对于j
的所有值,datos[j][2]欢迎,Gilberto,发布完整的错误跟踪,包括源代码位置,那就太好了。您是否介意更新您的帖子以符合此标准做法?@user3666197我已经更新了帖子。谢谢你的推荐!我忘了减少ca!让我看看这是否修复了代码。谢谢!我以这种方式结束了验证:if(j
是的,我想是的,j
一定有一些条件,因为它小于len(datos)
或len(ang0)
,无论什么合适。
while(ca>=0):
if(ca == 0):
i = i + 1
break
elif(datos[j][2] <= ca):
grupos[i].append(ang.index(angO[0]))
angO.remove(angO[0])
j = j + 1
elif(datos[j][2] > ca):
i = i + 1
break