@@ -57,16 +57,16 @@ def dijkstra(wg: WeightedGraph[V], root: V) -> Tuple[List[Optional[float]], Dict
5757 return distances , path_dict
5858
5959
60- # helper function to get easier access to dijkstra results
60+ # Helper function to get easier access to dijkstra results
6161def distance_array_to_vertex_dict (wg : WeightedGraph [V ], distances : List [Optional [float ]]) -> Dict [V , Optional [float ]]:
6262 distance_dict : Dict [V , Optional [float ]] = {}
6363 for i in range (len (distances )):
6464 distance_dict [wg .vertex_at (i )] = distances [i ]
6565 return distance_dict
6666
6767
68- # Takes a dictionary of edges to reach each node and returns an array of edges
69- # that goes from `start` to `end`
68+ # Takes a dictionary of edges to reach each node and returns a list of
69+ # edges that goes from `start` to `end`
7070def path_dict_to_path (start : int , end : int , path_dict : Dict [int , WeightedEdge ]) -> WeightedPath :
7171 if len (path_dict ) == 0 :
7272 return []
@@ -111,8 +111,11 @@ def path_dict_to_path(start: int, end: int, path_dict: Dict[int, WeightedEdge])
111111
112112 distances , path_dict = dijkstra (city_graph2 , "Los Angeles" )
113113 name_distance : Dict [str , Optional [int ]] = distance_array_to_vertex_dict (city_graph2 , distances )
114+ print ("Distances from Los Angeles:" )
114115 for key , value in name_distance .items ():
115116 print (f"{ key } : { value } " )
117+ print ("" ) # blank line
116118
119+ print ("Shortest path from Los Angeles to Boston:" )
117120 path : WeightedPath = path_dict_to_path (city_graph2 .index_of ("Los Angeles" ), city_graph2 .index_of ("Boston" ), path_dict )
118121 print_weighted_path (city_graph2 , path )
0 commit comments