Select Git revision
graph-get.py
-
Romain Vuillemot authoredRomain Vuillemot authored
graph-get.py 562 B
graph = { "a" : ["c"],
"b" : ["c", "e"],
"c" : ["a", "b", "d", "e"],
"d" : ["c"],
"e" : ["c", "b"],
"f" : []
}
def genere_arretes(graph):
edges = []
for node in graph:
for neighbour in graph[node]:
edges.append((node, neighbour))
return edges
# Affiche les sommets
print(list(graph.keys()))
# Affiche les arrêtes
print(genere_aretes(graph))
# >>> [('a', 'c'), ('c', 'a'), ('c', 'b'), ('c', 'd'), ('c', 'e'),
# ('b', 'c'), ('b', 'e'), ('e', 'c'), ('e', 'b'), ('d', 'c')]