Files

1.2 KiB

id, title, challengeType, dashedName
id title challengeType dashedName
65578c17d54dfab65cd54b95 Step 31 20 step-31

--description--

Since the algorithm begins its assessment from the starting node, after creating the paths dictionary, you need to add the starting node to its own list in the paths dictionary.

Use the append() method to append start to the paths[start] list.

--hints--

You should use the append() method to append start to paths[start].

({ test: () =>  {
    const shortest = __helpers.python.getDef(code, "shortest_path");
    const {function_body} = shortest;    
    assert(function_body.match(/^\s{4}paths\s*\[\s*start\s*\]\.append\s*\(\s*start\s*\)/m));
  }
})

--seed--

--seed-contents--

my_graph = {
    'A': [('B', 3), ('D', 1)],
    'B': [('A', 3), ('C', 4)],
    'C': [('B', 4), ('D', 7)],
    'D': [('A', 1), ('C', 7)]
}
--fcc-editable-region--
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}
    
    print(f'Unvisited: {unvisited}\nDistances: {distances}')
    
shortest_path(my_graph, 'A')
--fcc-editable-region--