【发布时间】:2017-01-25 07:14:45
【问题描述】:
我正在研究一些寻路算法,下面的 sn-p 应该在从目标到起点的路径中创建一个节点数组。当有从目标到起点的路径时,它可以正常工作。但是当没有从起点到终点的路径时,while 循环永远不会运行,结果将返回为[](这是正确的)。
def path(goal, pathToParentLookup):
currentNode = goal
result = []
while(currentNode in pathToParentLookup):
currentNode = pathToParentLookup[currentNode]
result.append(currentNode)
return result
#bidirectional search from start to goal finds the mid point of "center"
start_path = path(center, pathBack_start).reverse()
goal_path = path(center, pathBack_goal)
return start_path + [center] + goal_path
但是我收到了这个错误:
<ipython-input-14-ca3cb26b31ce> in bidirectional_search(graph, start, goal, searchMethod)
46 start_path = path(center, pathBack_start).reverse()
47 goal_path = path(center, pathBack_goal)
---> 48 return start_path + [center] + goal_path
49
50
TypeError: can only concatenate list (not "NoneType") to list
【问题讨论】:
标签: python list python-2.7 return nonetype