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

Tell us what’s happening:

Really stuck can’t see what’s wrong here? Indentations and if statement seem correct

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 = []
    distances = {}
    for node in graph:
        unvisited.append(node)
        if node == start:
            distances = 0

# User Editable Region

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) 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 28

assign 0 to that node inside the distances dictionary

distances is a dictionary that should have nodes as its keys. Hope this helps.

That makes sense but I’m unsure as how I would a value to a blank key i.e. don’t I need {‘key’,0}?

I gave {node:0} ago but that doesn’t seem to work

You need to assign 0 to the node key of distances. How do you assign a value to a key of an existing dictionary?

1 Like

Ahh thank you yeah that makes sense, all sorted

2 Likes