Return a set of couples that represents all of the edges. @input: graph (graph stored in an adjacency list where each vertex is represented as an integer) @example: >>> graph = {0: [1, 3], 1: [0, 3], 2: [0, 3], 3: [0, 1, 2]} >>> get_edges(graph) {(0, 1), (3, 1),
(graph: dict)
| 37 | |
| 38 | |
| 39 | def get_edges(graph: dict) -> set: |
| 40 | """ |
| 41 | Return a set of couples that represents all of the edges. |
| 42 | @input: graph (graph stored in an adjacency list where each vertex is |
| 43 | represented as an integer) |
| 44 | @example: |
| 45 | >>> graph = {0: [1, 3], 1: [0, 3], 2: [0, 3], 3: [0, 1, 2]} |
| 46 | >>> get_edges(graph) |
| 47 | {(0, 1), (3, 1), (0, 3), (2, 0), (3, 0), (2, 3), (1, 0), (3, 2), (1, 3)} |
| 48 | """ |
| 49 | edges = set() |
| 50 | for from_node, to_nodes in graph.items(): |
| 51 | for to_node in to_nodes: |
| 52 | edges.add((from_node, to_node)) |
| 53 | return edges |
| 54 | |
| 55 | |
| 56 | if __name__ == "__main__": |
no test coverage detected