def branching_weight(G, attr='weight', default=1):
 return sum((edge[2].get(attr, default) for edge in G.edges(data=True)))

def branching_weight ( G , attr = 'weight' , default = 1 ) : return sum ( ( edge [ 2 ] . get ( attr , default ) for edge in G . edges ( data = True ) ) )
returns the total weight of a branching .