mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-04-12 10:00:39 -04:00
1.4 KiB
1.4 KiB
id, title, challengeType, dashedName
| id | title | challengeType | dashedName |
|---|---|---|---|
| 655777060d8ddea6741be1b1 | Крок 32 | 20 | step-32 |
--description--
Усі відстані в distances встановлено як нескінченні, за винятком початкового вузла. Список unvisited містить всі вузли графа. Але насправді вам не потрібен цикл for, щоб досягти цього результату.
Видаліть цикл for та його тіло.
--hints--
Видаліть цикл for та весь вкладений код.
({ 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--