Files
2024-01-24 19:52:36 +01:00

1.6 KiB

id, title, challengeType, dashedName
id title challengeType dashedName
65578d0f6c78a0b868a43b9c Schritt 35 20 step-35

--description--

Inside the while loop, the first thing to do is define the current node to visit. For that you can use the min() function. It returns the smallest item from the iterable passed as the argument.

Remove pass, then create a variable called current and assign it min(unvisited).

--hints--

You should create a current variable in your while loop.

({ test: () =>  {
    const shortest = __helpers.python.getDef(code, "shortest_path");
    const {function_body} = shortest;    
    assert(function_body.match(/^(\s{4})while\s+unvisited\s*:\s*^\1\1current\s*=/ms));
  }
})

You should assign min(unvisited) to your current variable.

({ test: () =>  {
    const shortest = __helpers.python.getDef(code, "shortest_path");
    const {function_body} = shortest;    
    assert(function_body.match(/^(\s{4})while\s+unvisited\s*:\s*^\1\1current\s*=\s*min\s*\(\s*unvisited\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)]
}

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)
--fcc-editable-region--
    while unvisited:
        pass
--fcc-editable-region--    
    print(f'Unvisited: {unvisited}\nDistances: {distances}\nPaths: {paths}')

#shortest_path(my_graph, 'A')