class Graph (object) :
def __init__(self, nodes) :
self.nodes = nodes
self.adjList = {}
for node in self.nodes :
self.adjList[node] = []
def addEdges(self, u, v) :
self.adjList[u].append(v)
self.adjList[v].append(u)
def printGraph(self) :
for node in self.nodes :
print(f"{node} -> {self.adjList[node]}")
nodes = ["A", "B", "C", "D", "E"]
all_edges = [('A', 'B'), ('A', 'C'), ('C', 'D'), ('D', 'A'), ('D', 'E'), ('B', 'E')]
graph = Graph(nodes)
for u, v in all_edges :
graph.addEdges(u, v)
graph.printGraph()