Files

1.3 KiB

id, title, challengeType, dashedName
id title challengeType dashedName
655777060d8ddea6741be1b1 Step 27 20 step-27

--description--

All the distances in distances are set to infinite, except for the starting node. The unvisited list contains all the nodes in your graph. But actually, you don't need that for loop to achieve this result.

Remove your for loop with its entire body.

--hints--

You should remove your for loop and all the nested code.

({ test: () =>  {
    const shortest = __helpers.python.getDef(code, "shortest_path");
    const {function_body} = shortest;    
    assert(function_body.match(/(^\s*)distances\s*=\s*\{\s*\}\s*\1print\s*\(\s*f("|')Unvisited:\s*\{\s*unvisited\s*\}\\nDistances:\s\{\s*distances\s*\}\2\s*\)/ms));
  }
})

--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 = []
    distances = {}
    for node in graph:
        unvisited.append(node)
        if node == start:
            distances[node] = 0
        else:
            distances[node] = float('inf')
    print(f'Unvisited: {unvisited}\nDistances: {distances}')
    
shortest_path(my_graph, 'A')
--fcc-editable-region--