1.8 KiB
id, title, challengeType, dashedName
| id | title | challengeType | dashedName |
|---|---|---|---|
| 655771d889132f9ccd341060 | Schritt 15 | 20 | step-15 |
--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 the following distances:
| Edge | Weight |
|---|---|
| A-B | 3 |
| B-C | 4 |
| C-D | 7 |
| D-A | 1 |
--hints--
Your dictionary should have 4 keys called A, B, C, and D.
({ test: () => assert(__pyodide.runPython(`
graph = __locals.get("my_graph")
key_list = ["A", "B", "C", "D"]
len(graph) == 4 and all(key in graph for key in key_list)
`))
})
my_graph["A"] should be a list of tuples.
({ test: () => assert(__pyodide.runPython(`
graph = __locals.get("my_graph")
type(graph["A"]) is list and all(type(i) is tuple for i in graph["A"])
`))
})
my_graph["A"] should be a list of tuples where the first item in the tuple is the connected node and the second item is the distance.
({ test: () => assert(__pyodide.runPython(`
graph = __locals.get("my_graph")
tuples = [("B", 3), ("D", 1)]
len(graph["A"]) == 2 and all(t in graph["A"] for t in tuples)
`))
})
--seed--
--seed-contents--
--fcc-editable-region--
my_graph = {
'A': ['B', 'D'],
--fcc-editable-region--
'B': ['A', 'C'],
'C': ['B', 'D'],
'D': ['A', 'C']
}