MCPcopy Index your code
hub / github.com/subbarayudu-j/TheAlgorithms-Python / AdjacencyList

Class AdjacencyList

Graphs/graph.py:9–22  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

7# We can use Python's dictionary for constructing the graph
8
9class AdjacencyList(object):
10 def __init__(self):
11 self.List = {}
12
13 def addEdge(self, fromVertex, toVertex):
14 # check if vertex is already present
15 if fromVertex in self.List.keys():
16 self.List[fromVertex].append(toVertex)
17 else:
18 self.List[fromVertex] = [toVertex]
19
20 def printList(self):
21 for i in self.List:
22 print((i,'->',' -> '.join([str(j) for j in self.List[i]])))
23
24if __name__ == '__main__':
25 al = AdjacencyList()

Callers 1

graph.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected