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

Method __init__

graphs/dijkstra_alternate.py:5–16  ·  view source on GitHub ↗

>>> graph = Graph(2) >>> graph.vertices 2 >>> len(graph.graph) 2 >>> len(graph.graph[0]) 2

(self, vertices: int)

Source from the content-addressed store, hash-verified

3
4class Graph:
5 def __init__(self, vertices: int) -> None:
6 """
7 >>> graph = Graph(2)
8 >>> graph.vertices
9 2
10 >>> len(graph.graph)
11 2
12 >>> len(graph.graph[0])
13 2
14 """
15 self.vertices = vertices
16 self.graph = [[0] * vertices for _ in range(vertices)]
17
18 def print_solution(self, distances_from_source: list[int]) -> None:
19 """

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected