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

1.6 KiB

id, title, challengeType, dashedName
id title challengeType dashedName
65661b72d6745ebec6a96923 Step 22 20 step-22

--description--

In the same way, modify the remaining two lists considering that the C-D distance is 7.

--hints--

my_graph['C'] should be a list containing the tuples ('B', 4) and ('D', 7).

({ test: () => assert(runPython(`
    tuples = [("B", 4), ("D", 7)]
    len(my_graph["C"]) == 2 and all(t in my_graph["C"] for t in tuples) 
  `))
})

my_graph['D'] should be a list containing the tuples ('A', 1) and ('C', 7).

({ test: () => assert(runPython(`
    tuples = [("A", 1), ("C", 7)]
    len(my_graph["D"]) == 2 and all(t in my_graph["D"] for t in tuples)
  `))
})

my_graph should have 4 keys named 'A', 'B', 'C', and 'D'.

({ test: () => assert(runPython(`
    key_list = ["A", "B", "C", "D"]
    len(my_graph) == 4 and all(key in my_graph for key in key_list)
  `))
})

my_graph['A'] should be a list containing the tuples ('B', 3) and ('D', 1).

({ test: () => assert(runPython(`
    tuples = [("B", 3), ("D", 1)]
    len(my_graph["A"]) == 2 and all(t in my_graph["A"] for t in tuples)
  `))
})

my_graph['B'] should be a list containing the tuples ('A', 3) and ('C', 4).

({ test: () => assert(runPython(`
    tuples = [("A", 3), ("C", 4)]
    len(my_graph["B"]) == 2 and all(t in my_graph["B"] for t in tuples)
  `))
})

--seed--

--seed-contents--

--fcc-editable-region--
my_graph = {
    'A': [('B', 3), ('D', 1)],
    'B': [('A', 3), ('C', 4)],
    'C': ['B', 'D'],
    'D': ['A', 'C']
}
--fcc-editable-region--