mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-03-06 06:39:18 -05:00
1.4 KiB
1.4 KiB
id, title, challengeType, dashedName
| id | title | challengeType | dashedName |
|---|---|---|---|
| 655774955b097ea14897db12 | Step 23 | 20 | step-23 |
--description--
The distance from the starting node is zero, because the algorithm begins its assessment right from there.
After appending node to unvisited in your loop, create an if statement that triggers if the node is equal to the starting node. Then assign 0 to that node inside the distances dictionary.
--hints--
You should create an if statement that executes when node is equal to start.
({ test: () => {
const shortest = __helpers.python.getDef(code, "shortest_path");
const {function_body} = shortest;
assert(function_body.match(/^(\s*)for.*:.*^\1\1if\s+node\s*==\s*start\s*:/ms));
}
})
Inside your new if statement you should assign 0 to the node in the distances dictionary.
({ test: () => {
const shortest = __helpers.python.getDef(code, "shortest_path");
const {function_body} = shortest;
assert(function_body.match(/^(\s*)for.*:.*^\1\1if\s+node\s*==\s*start\s*:\s*^\1\1\1distances\s*\[\s*node\s*\]\s*=\s*0/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)
--fcc-editable-region--