Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def shortest_path(graph, origin, destination):
- if origin == destination:
- raise ValueError("The same destination as origin")
- visited, paths = dijkstra(graph, origin)
- full_path = deque()
- _destination = paths[destination]
- while _destination != origin:
- full_path.appendleft(_destination)
- _destination = paths[_destination]
- full_path.appendleft(origin)
- full_path.append(destination)
- return visited[destination], list(full_path)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement