curriculum/challenges/english/blocks/learn-algorithm-design-by-building-a-shortest-path-algorithm/6557910b0ebaeebc18209e90.md
Now remove pass and assign paths[current] to paths[node].
You should delete pass and assign paths[current] to paths[node].
({ test: () => {
const shortest = __helpers.python.getDef(code, "shortest_path");
const {function_body} = shortest;
assert(function_body.match(/^(\s*)if.*:.*^\1(\s{4})if\s+paths\s*\[\s*node\s*\]\s*\[\s*-\s*1\s*\]\s*==\s*node\s*:\s*^\1\2\2paths\s*\[\s*node\s*\]\s*=\s*paths\s*\[\s*current\s*\]/ms));
}
})
my_graph = {
'A': [('B', 3), ('D', 1)],
'B': [('A', 3), ('C', 4)],
'C': [('B', 4), ('D', 7)],
'D': [('A', 1), ('C', 7)]
}
def shortest_path(graph, start):
unvisited = list(graph)
distances = {node: 0 if node == start else float('inf') for node in graph}
paths = {node: [] for node in graph}
paths[start].append(start)
--fcc-editable-region--
while unvisited:
current = min(unvisited, key=distances.get)
for node, distance in graph[current]:
if distance + distances[current] < distances[node]:
distances[node] = distance + distances[current]
if paths[node][-1] == node:
pass
--fcc-editable-region--
print(f'Unvisited: {unvisited}\nDistances: {distances}\nPaths: {paths}')
#shortest_path(my_graph, 'A')