Skip to content
Snippets Groups Projects
Select Git revision
  • 7ff9de0a7e92082b49b7938fc2abe3daa60057df
  • master default protected
2 results

graph-get.py

Blame
  • 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')]