To create nodes in Networkx, you simply need to call the add_node() function on a Graph object. Here's an example:
main.py279 chars17 lines
This will output:
main.py72 chars2 lines
So we can see that each node is represented as a tuple, with the node ID as the first element and a dictionary of node attributes as the second element (which is empty if no attributes were given).
Note that you can also add nodes with edges at the same time using add_edge(), or add edges separately after adding nodes.
gistlibby LogSnag