Learn Algorithm Design by Building a Shortest Path Algorithm - Step 34

Tell us what’s happening:

I have assigned each node ‘A’, ‘B’, ‘C’, ‘D’ and empty list and this can be displayed if you use print(paths) below the declared variable.

From my understanding, this is the objective of the question. Could anyone help identify the lapse in my understanding of the problem?

Your code so far

my_graph = {
    'A': [('B', 3), ('D', 1)],
    'B': [('A', 3), ('C', 4)],
    'C': [('B', 4), ('D', 7)],
    'D': [('A', 1), ('C', 7)]
}


# User Editable Region

def shortest_path(graph, start):
    unvisited = list(graph)
    distances = {}
    paths = {node: [] for node in my_graph}
    print(f'Unvisited: {unvisited}\nDistances: {distances}')
    
shortest_path(my_graph, 'A')

# User Editable Region

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36

Challenge Information:

Learn Algorithm Design by Building a Shortest Path Algorithm - Step 34

This issue has been self-resolved. I found just need to change my_graph to graph.

1 Like