पायथन में एक ग्राफ को पार करते समय, मैं यह त्रुटि प्राप्त कर रहा हूं:
'तानाशाह' वस्तु में कोई विशेषता नहीं है 'has_key'
यहाँ मेरा कोड है:
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
कोड का उद्देश्य एक नोड से दूसरे तक के रास्तों को खोजना है। कोड स्रोत: http://cs.mwsu.edu/~terry/courses/4883/lectures/graphs.html
मुझे यह त्रुटि क्यों हो रही है और मैं इसे कैसे ठीक कर सकता हूं?
if not start in graph: