Files
2024-05-22 17:27:37 +02:00

1.2 KiB

id, title, challengeType, dashedName
id title challengeType dashedName
6557746aad2844a0cd864e12 Step 27 20 step-27

--description--

While the algorithm explores the graph, it should keep track of the currently known shortest distance between the starting node and the other nodes.

Before your for loop, create a new variable named distances and assign it an empty dictionary.

--hints--

You should have a variable named distances.

({ test: () =>  {
    const shortest = __helpers.python.getDef(code, "shortest_path");
    const {function_body} = shortest;    
    assert(function_body.match(/^(\s*)distances\s*=.*(?=^\1for.*:)/ms));
  }
})

Your distances variable should be an empty dictionary.

({ test: () =>  {
    const shortest = __helpers.python.getDef(code, "shortest_path");
    const {function_body} = shortest;    
    assert(function_body.match(/^(\s*)distances\s*=\s*\{\s*\}.*(?=^\1for.*:)/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 = []
    for node in graph:
        unvisited.append(node)
--fcc-editable-region--