How do I generate an adjacency matrix of a graph from a dictionary in python?
问题 I have the following dictionary: g = { 'A': ['A', 'B', 'C'], 'B': ['A', 'C', 'E'], 'C': ['A', 'B', 'D'], 'D': ['C','E'], 'E': ['B','D'] } It implements a graph, each list contains the neighbors of the graph vertices (dictionary keys are the vertices itself). I'm in trouble, I can not think of a way to get a graph adjacency matrix from their lists of neighbors, might be easy but I am new to python, I hope someone can help me! I am using Python 3.5 I need to generate the following matrix: 回答1: