def degree_centrality(G, nodes):
 top = set(nodes)
 bottom = (set(G) - top)
 s = (1.0 / len(bottom))
 centrality = dict(((n, (d * s)) for (n, d) in G.degree(top)))
 s = (1.0 / len(top))
 centrality.update(dict(((n, (d * s)) for (n, d) in G.degree(bottom))))
 return centrality

def degree_centrality ( G , nodes ) : top = set ( nodes ) bottom = ( set ( G ) - top ) s = ( 1.0 / len ( bottom ) ) centrality = dict ( ( ( n , ( d * s ) ) for ( n , d ) in G . degree ( top ) ) ) s = ( 1.0 / len ( top ) ) centrality . update ( dict ( ( ( n , ( d * s ) ) for ( n , d ) in G . degree ( bottom ) ) ) ) return centrality
compute the degree centrality for nodes .