mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2025-12-23 21:04:36 -05:00
1.4 KiB
1.4 KiB
id, title, challengeType, dashedName
| id | title | challengeType | dashedName |
|---|---|---|---|
| 6557743527cb92a06417ea97 | Step 26 | 20 | step-26 |
--description--
Create a for loop to iterate over your graph, and use the .append() method to add each node to the end of the unvisited list.
--hints--
You should create a for loop to iterate over graph inside the shortest_path function.
({ test: () => {
const commentless_code = __helpers.python.removeComments(code);
const {function_body} = __helpers.python.getDef(commentless_code, "shortest_path");
assert(function_body.match(/^\s*for\s+\w+\s+in\s+graph\s*:/m));
}
})
You should append each node to unvisited inside your for loop.
({ test: () => {
const commentless_code = __helpers.python.removeComments(code);
const block_regex = /for\s+(\w+)\s+in\s+graph\s*/;
const {block_body} = __helpers.python.getBlock(commentless_code, block_regex);
const loop_condition = commentless_code.match(block_regex);
const regex = new RegExp(`^\\s+unvisited\\.append\\s*\\(\\s*${loop_condition[1]}\\s*\\)`, "m");
assert(block_body.match(regex));
}
})
--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 = []
--fcc-editable-region--