Files
2024-05-29 10:06:17 -07:00

1.5 KiB

id, title, challengeType, dashedName
id title challengeType dashedName
6557743527cb92a06417ea97 Крок 26 20 step-26

--description--

Створіть цикл for, щоб ітерувати над графом та використайте метод .append(), щоб додати всі вузли до кінця списку unvisited.

--hints--

Створіть цикл for, щоб ітерувати над graph в межах функції shortest_path.

({ 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));
  }
})

Додайте всі вузли до unvisited в межах циклу for.

({ 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--