Files
freeCodeCamp/curriculum/challenges/english/blocks/learn-algorithm-design-by-building-a-shortest-path-algorithm/65577739f57ecca6c39bb4e9.md
2025-08-26 12:37:26 +02:00

1.2 KiB

id, title, challengeType, dashedName
id title challengeType dashedName
65577739f57ecca6c39bb4e9 Step 33 20 step-33

--description--

The list() type constructor enables you to build a list from an iterable.

Modify the assignment of your unvisited variable to use list(), and pass graph as the iterable.

--hints--

You should use list() to generate a list from the graph dictionary.

({ test: () =>  {
    const shortest = __helpers.python.getDef(code, "shortest_path");
    const {function_body} = shortest;    
    assert(function_body.match(/list\s*\(\s*graph\s*\)/));
  }
})

You should assign list(graph) to unvisited.

({ test: () =>  {
    const shortest = __helpers.python.getDef(code, "shortest_path");
    const {function_body} = shortest;    
    assert(function_body.match(/unvisited\s*=\s*list\s*\(\s*graph\s*\)/));
  }
})

--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 = {}
    
    print(f'Unvisited: {unvisited}\nDistances: {distances}')
    
shortest_path(my_graph, 'A')
--fcc-editable-region--