mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-04-12 01:00:13 -04:00
1.6 KiB
1.6 KiB
id, title, challengeType, dashedName
| id | title | challengeType | dashedName |
|---|---|---|---|
| 655774955b097ea14897db12 | Step 28 | 20 | step-28 |
--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 commentless_code = __helpers.python.removeComments(code);
const {block_body} = __helpers.python.getBlock(commentless_code, /for\s+node\s+in\s+graph\s*/);
assert(block_body.match(/unvisited\.append\s*\(\s*node\s*\)\s*^\s+if\s+(node\s*==\s*start|start\s*==\s*node)\s*:/m));
}
})
Inside your new if statement you should assign 0 to the node in the distances dictionary.
({ test: () => {
const commentless_code = __helpers.python.removeComments(code);
const {block_body} = __helpers.python.getBlock(commentless_code, /if\s+(node\s*==\s*start|start\s*==\s*node)\s*/m);
assert(block_body.match(/^\s+distances\s*\[\s*node\s*\]\s*=\s*0/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 = []
distances = {}
for node in graph:
unvisited.append(node)
--fcc-editable-region--