def intra_community_edges(G, partition):
 return sum((G.subgraph(block).size() for block in partition))

def intra_community_edges ( G , partition ) : return sum ( ( G . subgraph ( block ) . size ( ) for block in partition ) )
returns the number of intra-community edges according to the given partition of the nodes of g .