MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / initialize_weighted_undirected_graph

Function initialize_weighted_undirected_graph

graphs/basic_graphs.py:35–46  ·  view source on GitHub ↗
(
    node_count: int, edge_count: int
)

Source from the content-addressed store, hash-verified

33
34
35def initialize_weighted_undirected_graph(
36 node_count: int, edge_count: int
37) -> dict[int, list[tuple[int, int]]]:
38 graph: dict[int, list[tuple[int, int]]] = {}
39 for i in range(node_count):
40 graph[i + 1] = []
41
42 for e in range(edge_count):
43 x, y, w = (int(i) for i in _input(f"Edge {e + 1}: <node1> <node2> <weight> "))
44 graph[x].append((y, w))
45 graph[y].append((x, w))
46 return graph
47
48
49if __name__ == "__main__":

Callers

nothing calls this directly

Calls 2

_inputFunction · 0.85
appendMethod · 0.45

Tested by

no test coverage detected