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

Tell us what’s happening:

Describe your issue in detail here.
I don’t really know what im doing wrong here

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 = {for key in graph}
    
    print(f'Unvisited: {unvisited}\nDistances: {distances}')
    
shortest_path(my_graph, 'A')

# User Editable Region

Your browser information:

User Agent is: Mozilla/5.0 (X11; CrOS x86_64 14541.0.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36

Challenge Information:

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

You appear to have created this post without editing the template. Please edit your post to Tell us what’s happening in your own words.

Good but you are missing an element from this dict comprehension:

{key: val for key in dict}
{<do this> for <this> in <that>}

https://www.geeksforgeeks.org/python-dictionary-comprehension/

1 Like

Hi, thanks for the reply:
I tried changing it but I still cant get it right

paths = {key: [] for key in graph}

I added an empty list before the ‘for’ because it says to add an empty list to the key, maybe I haven`t fully understood the problem because I can’t figure it out.

Edit: Nevermind I just deleted it and wrote it again and it worked, there was probably an error with the spacing

2 Likes

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.