PythiloHard · 35 min · Task 17 of 20 · progress kept in this browser

Cheapest route

A map is a dict from each place to (neighbour, cost) pairs, with no negative costs. Find the cheapest route between two places and the route itself.

g = {"a": [("b", 7), ("c", 1)],
     "c": [("b", 2)], "b": []}
cheapest_route(g, "a", "b")
# (3, ["a", "c", "b"])
Your task

Write cheapest_route(graph, start, goal) returning (total_cost, path), where path is the list of places from start to goal, or None if goal cannot be reached. Use heapq. A place may appear only as a neighbour, without a key of its own.