Advertisement
Guest User

Untitled

a guest
Feb 20th, 2020
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.48 KB | None | 0 0
  1. def shortest_path(graph, origin, destination):
  2.     if origin == destination:
  3.         raise ValueError("The same destination as origin")
  4.     visited, paths = dijkstra(graph, origin)
  5.     full_path = deque()
  6.     _destination = paths[destination]
  7.  
  8.     while _destination != origin:
  9.         full_path.appendleft(_destination)
  10.         _destination = paths[_destination]
  11.  
  12.     full_path.appendleft(origin)
  13.     full_path.append(destination)
  14.  
  15.     return visited[destination], list(full_path)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement