定义了两个函数,visited_to_route()和calculate_cost()。第一个函数的输出是第二个函数的输入。
第一个函数能正常运行,返回值为列表嵌套列表。
如果这样调用:
ant_routes = visited_to_route()
calculate_cost(ant_routes)
会报错:IndexError: list index out of range
但是如果把ant_routes的值复制下来,这样调用:
ant_routes=[[0, 15.0, 8.0, 6.0, 26.0, 36.0, 13.0, 2.0, 11.0, 41.0, 43.0, 0].....[0, 34.0, 10.0, 12.0, 5.0, 7.0, 4.0, 47.0, 27.0, 24.0, 0]]
#ant_routes = visited_to_route()
calculate_cost(ant_routes)
就正常运行了!
请问这是什么原因呀?既然复制ant_routes能正常运行第二个程序,就应该没有IndexError呀