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

I’ve tried many forms of lists and tuples , and I can’t seem to get it. Correct my code for me.

Your code so far


# User Editable Region

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

# 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/120.0.0.0 Safari/537.36 Edg/120.0.0.0

Challenge Information:

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

my_graph should be a dictionary with 2 keys. You don’t need to change the whole data structure, but only the value of the A key.

You have a list of strings as the value of the A key: ['B', 'D']
You need to change it into a list of tuples: [(j, k), (l, m)]
where the first item is the connected node (which is already in the list you have) and the second item is the distance, for each tuple. I suggest you to reset the code before trying again.

Does the new list have quotations for both keys and weights , or do they only apply to the keys?

The weights need to be integers, not strings.

1 Like

my_graph = {
‘A’: [(‘B’, 3), (‘D’, 1],
‘B’: [(‘A’, 3), (‘C’, 4)],
‘C’: [(‘B’, 4), (‘D’, 7)],
‘D’: [(‘A’, 1), (‘C’, 7)]
}
This is my code so far, I’ve followed your directives and it still won’t proceed.

I assume you realized that there was a syntax error.

Did you solve it already?

You should only complete the first line here. If you reset the problem, only the line for ‘A’ is in the editable area.

Hi did you have to download the file “given data” in order to get your graphs?

There’s no file to download. Honestly, I don’t understand the question.

When I watch the tutorials (the YouTube videos) they say we must download the file but I can’t figure out how to download them in order for me to be able to do the exercises.

How do I get the graphs showing while working

There’s no video tutorials for this course. You are probably referring to the legacy Python for everybody course.

The new certification replaced the one with video tutorials.

So how do I get the new one because ever since I’ve signed up with free code camp they’ve been mailing me tutorials

You are changing the dictionary dont do, and your first node should be b and D , two touples inside a list-------------removed

Hey pal! in the step 15 you just type 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.

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.