The following steps will identify key players in this network of comic book characters:
- To find the top ten nodes in the heroes network, we compute the nodes' degree and sort them:
import operator>>> degrees = sorted(graph.degree().items(), key=operator.itemgetter(1), reverse=True)>>> for node in degrees: print node
- Additionally, we compute the percent of nodes in the graph that a node is connected to; NetworkX provides a helpful function, degree_centrality, to do this for us. While we're at it, we might as well also set this as a property for our nodes for easy lookup:
>>> centrality = nx.degree_centrality(graph)>>> nx.set_node_attribues(graph, 'centrality', centrality)>>> degrees = sorted(centrality.items(), key=itemgetter(1), ...