Depending on your needs, you might find that you also require the ability to create
172
PART 3
Exploring the World of Graphs
performs various analysis tasks on graphs. You can see one such example at
https://www.python.org/doc/essays/graphs/
. The following code shows how
to create a dictionary of lists for the example graph:
nx.to_dict_of_lists(AGraph)
{1: [2, 3, 5, 6], 2: [1, 3], 3: [1, 2, 4], 4: [3, 5],
5: [1, 4], 6: [1]}
Notice that each node represents a dictionary entry, followed by a list of the nodes
to which it connects. For example, node 1 connects to nodes 2, 3, 5, and 6.