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

Tell us what’s happening:

I am setting the node inside the dictionary to zero, but its still not working

``````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 = {node: 0}

/* User Editable Region */

``````

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

Challenge Information:

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

Hello Iswoboda!

You are very close, but that’s not how we set `0` to a list.
Its very similar to how you would get a character out of a string. You’re very close though!
You only have to adjust the part after `distances`.

2 Likes

I tried changing the colon to a comma, and putting the zero in quotes, but this doesn’t work. Any other ways?

As a hint if I wanted to change a specific node I would do so by using `distances[specific_node] = #whatever you wante to change it to.`
So you will have to adjust that to make sure the current node is set to 0. Your logic is there, but the formatting wasn’t yet, hope this helps.

2 Likes

Hi,

Think of it like you want to take the values in the variable node and assign it a value of zero.

Your code should look like the one below.
distances[your_variable] = assigned value

1 Like

reading the comments it should look like this but the code still doesnt pass

–solution removed—

Hi, please open a new topic for help on this, thanks!

Your code does look correct. Make sure it’s indented correctly in relation to the rest of the function?

If you have a question about a specific challenge as it relates to your written code for that challenge and need some help, click the Ask for Help button located on the challenge (it looks like a question mark). This button only appears if you have tried to submit an answer at least three times.

The Ask for Help button will create a new topic with all code you have written and include a link to the challenge also. You will still be able to ask any questions in the post before submitting it to the forum.

Thank you.

should be like this:

–removed–

It is great that you solved the challenge, but instead of posting your full working solution, it is best to stay focused on answering the original poster’s question(s) and help guide them with hints and suggestions to solve their own issues with the challenge.

We are trying to cut back on the number of spoiler solutions found on the forum and instead focus on helping other campers with their questions and definitely not posting full working solutions.