mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-04-12 10:00:39 -04:00
1.3 KiB
1.3 KiB
id, title, challengeType, dashedName
| id | title | challengeType | dashedName |
|---|---|---|---|
| 65578c17d54dfab65cd54b95 | Крок 36 | 20 | step-36 |
--description--
Оскільки алгоритм починає оцінювання з початкового вузла, після створення словника paths потрібно додати початковий вузол до його власного списку в словнику paths.
Використайте метод .append(), щоб додати start до списку paths[start].
--hints--
Використайте метод .append(), щоб додати start до 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*\]\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--