mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-04-12 01:00:13 -04:00
1.3 KiB
1.3 KiB
id, title, challengeType, dashedName
| id | title | challengeType | dashedName |
|---|---|---|---|
| 655771d889132f9ccd341060 | Step 20 | 20 | step-20 |
--description--
A graph is called a weighted graph when its edges are associated with weights, representing a distance, time or other quantitative value.
In your case, these weights will be the distances between each node, or point in space. To represent a weighted graph you can modify your dictionary, using a list of tuples for each value.
The first element in the tuple will be the connected node, and the second element will be an integer number indicating the distance.
Modify my_graph['A'] into a list of tuples, considering that the A-B distance is 3 and the A-D distance is 1.
--hints--
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 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)
`))
})
--seed--
--seed-contents--
--fcc-editable-region--
my_graph = {
'A': ['B', 'D'],
--fcc-editable-region--
'B': ['A', 'C'],
'C': ['B', 'D'],
'D': ['A', 'C']
}