def cut_size(G, S, T=None, weight=None):
 edges = nx.edge_boundary(G, S, T, data=weight, default=1)
 if G.is_directed():
  edges = chain(edges, nx.edge_boundary(G, T, S, data=weight, default=1))
 return sum((weight for (u, v, weight) in edges))

def cut_size ( G , S , T = None , weight = None ) : edges = nx . edge_boundary ( G , S , T , data = weight , default = 1 ) if G . is_directed ( ) : edges = chain ( edges , nx . edge_boundary ( G , T , S , data = weight , default = 1 ) ) return sum ( ( weight for ( u , v , weight ) in edges ) )
returns the size of the cut between two sets of nodes .