En parcourant un graphique en Python, je reçois cette erreur:
L'objet 'dict' n'a pas d'attribut 'has_key'
Voici mon code:
def find_path(graph, start, end, path=[]):
path = path + [start]
if start == end:
return path
if not graph.has_key(start):
return None
for node in graph[start]:
if node not in path:
newpath = find_path(graph, node, end, path)
if newpath: return newpath
return None
Le code vise à trouver les chemins d'un nœud à d'autres. Source du code: http://cs.mwsu.edu/~terry/courses/4883/lectures/graphs.html
Pourquoi est-ce que j'obtiens cette erreur et comment puis-je la corriger?
if not start in graph: