def transitivity(G):
 triangles = sum((t for (v, d, t, _) in _triangles_and_degree_iter(G)))
 contri = sum(((d * (d - 1)) for (v, d, t, _) in _triangles_and_degree_iter(G)))
 return (0 if (triangles == 0) else (triangles / contri))

def transitivity ( G ) : triangles = sum ( ( t for ( v , d , t , _ ) in _triangles_and_degree_iter ( G ) ) ) contri = sum ( ( ( d * ( d - 1 ) ) for ( v , d , t , _ ) in _triangles_and_degree_iter ( G ) ) ) return ( 0 if ( triangles == 0 ) else ( triangles / contri ) )
compute graph transitivity .