summaryrefslogtreecommitdiff
path: root/graph.py
diff options
context:
space:
mode:
Diffstat (limited to 'graph.py')
-rw-r--r--graph.py6
1 files changed, 3 insertions, 3 deletions
diff --git a/graph.py b/graph.py
index 573a1ba..ddd5abd 100644
--- a/graph.py
+++ b/graph.py
@@ -189,16 +189,16 @@ def has_path(graph_dict, fromnode, tonode, path=None):
node has key associated to a list of nodes directly reachable from it.
Return None if no path exists to go from `fromnode` to `tonode`, else the
- first path found
+ first path found (as a list including the destination node at last)
"""
if path is None:
path = []
elif fromnode in path:
- return False
+ return None
path.append(fromnode)
for destnode in graph_dict[fromnode]:
if destnode == tonode or has_path(graph_dict, destnode, tonode, path):
- return path[1:]
+ return path[1:] + [tonode]
path.pop()
return None