-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgraph.py
More file actions
40 lines (22 loc) · 794 Bytes
/
Copy pathgraph.py
File metadata and controls
40 lines (22 loc) · 794 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
class Graph:
def __init__(self,graph_dic=None):
if graph_dic == None:
graph_dic = {}
self.__graph_dic = graph_dic
def verticies(self):
return self.__graph_dic.keys()
'''def Edges(self):
return self.__graph_dic.values()
'''
def Edges(self):
edges = []
for node in self.__graph_dic:
for neig in self.__graph_dic[node]:
edges.append((node,neig))
return edges
def main():
gd = {"a":["c"],"b":["c","e"],"c":["a","b","d","e"],"d":["c"],"e":["b","c"],"f":[]}
graph = Graph(gd)
print(graph.verticies())
print(graph.Edges())
main()