The shortest route itself

Write shortest_path(graph, start, goal) that returns the list of nodes on a shortest route from start to goal in a two-way graph, including both ends, or [] if there is none. When several shortest routes exist, return the one BFS finds when neighbours are explored in the order they are listed.

graph = {"A": ["B", "C"], "B": ["A", "D"], "C": ["A", "D"], "D": ["B", "C", "E"], "E": ["D"]}
shortest_path(graph, "A", "E")  ->  ["A", "B", "D", "E"]
shortest_path(graph, "A", "A")  ->  ["A"]
shortest_path({"A": [], "B": []}, "A", "B")  ->  []

The point is to practise recording predecessors during BFS and walking them back.

def shortest_path(graph, start, goal):
    ...