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

I am struggling with how to append the paths dictionary. I know it states to create a list for a starting node. Here’s what I have. I have manipulated it a few ways and still get errors.

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

I have also tried:

paths.append(paths[start])

Nvm, I got it. I overthought the situation.

paths[start].append(start)

for whatever reason throwing start on there twice felt wrong

2 Likes