我正在打印一个我认为是一个列表的值,但是我得到的输出是:[...]
这代表什么?我如何测试它?我试过:
^{pr2}$
以及myVar.__repr_() != Ellipsis
但是没有骰子。。。在
以下是导致问题的代码缩减:def buildPaths(graph, start, end, path=[], totalPaths=[]):
"""
returns list of all possible paths from start node to the end node
"""
path = path + [start]
if start == end:
return path
for nextNode in graph.childrenOf(start):
if nextNode not in path:
newPath = buildPaths(graph, nextNode, end, path, totalPaths)
if newPath != []: # test
totalPaths.append(newPath)
return totalPaths
totalPaths包含许多[…]本应是递归列表,但我不明白为什么。为了防止这种情况的发生,我改变了测试。在
我也试过:def buildPaths(graph, thisNode, end, path=[], totalPaths=None):
"""
returns list of all possible paths from start node to the end node
"""
path = path + [thisNode]
if thisNode == end:
return path
for nextNode in graph.childrenOf(thisNode):
if nextNode not in path:
newPath = buildPaths(graph, nextNode, end, path, totalPaths)
if newPath != None:
if totalPaths == None:
totalPaths = [newPath]
else:
totalPaths.append(newPath)
return totalPaths
为空路径显式返回None。在