I'm a beginner trying to use python. The code I'm working with is from http://www.python.org/doc/essays/graphs/ The goal is to obtain a path between two nodes using a dictionary and a recursive function. When I run it, I don't get any output or any errors. I'm mainly looking for somekind of pointer as to what could cause this.
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
graph = {'A': ['B','C'],'B': ['C','D'],'C': ['D'],'D': ['C'],'E': ['F'],'F': ['C']}
find_path(graph,'A','D')