我是 python 新手,我试图理解这里的一个基本错误。我在下面的代码中收到 TypeError: 'list' object is not callable 错误。有人可以解释一下我的代码有什么问题吗?
graph = {'a': ['b', 'c'], 'b': ['a', 'c'], 'c': ['b', 'd'], 'd': ['a'], 'e': ['a']}
def reachable(graph, node):
res = [node]
reachable = graph[node]
for currentnode in reachable:
if currentnode not in res :
reachableNodes = reachable(graph,currentnode) << TypeError:
for newNode in reachableNodes:
if newNode not in res :
res.append(newNode)
return res
错误:类型错误:“列表”对象不可调用错误
您通过执行以下操作隐藏了函数名称reachable = graph[node]
。使用不同的名称。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)