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

1.2 KiB

id, title, challengeType, dashedName
id title challengeType dashedName
65578c74607d40b6d8c4757f Step 37 20 step-37

--description--

Add \nPaths: {paths} at the end of the f-string passed to the print call, so that it prints the paths variable, too.

--hints--

You should modify your existing print call by adding \nPaths: {paths} at the end of the f-string.

({ test: () =>  {
    const shortest = __helpers.python.getDef(code, "shortest_path");
    const {function_body} = shortest;    
    assert(function_body.match(/^\s{4}print\s*\(\s*f("|')Unvisited:\s*\{\s*unvisited\s*\}\\nDistances:\s\{\s*distances\s*\}\\nPaths:\s\{\s*paths\s*\}\1\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 = list(graph)
    distances = {node: 0 if node == start else float('inf') for node in graph}
    paths = {node: [] for node in graph}
    paths[start].append(start)

    print(f'Unvisited: {unvisited}\nDistances: {distances}')

shortest_path(my_graph, 'A')
--fcc-editable-region--