@not_implemented_for('directed')
def clustering(G, nodes=None, weight=None):
 if (weight is not None):
  td_iter = _weighted_triangles_and_degree_iter(G, nodes, weight)
  clusterc = {v: (0 if (t == 0) else (t / (d * (d - 1)))) for (v, d, t) in td_iter}
 else:
  td_iter = _triangles_and_degree_iter(G, nodes)
  clusterc = {v: (0 if (t == 0) else (t / (d * (d - 1)))) for (v, d, t, _) in td_iter}
 if (nodes in G):
  return clusterc[nodes]
 return clusterc

@ not_implemented_for ( 'directed' ) def clustering ( G , nodes = None , weight = None ) : if ( weight is not None ) : td_iter = _weighted_triangles_and_degree_iter ( G , nodes , weight ) clusterc = { v : ( 0 if ( t == 0 ) else ( t / ( d * ( d - 1 ) ) ) ) for ( v , d , t ) in td_iter } else : td_iter = _triangles_and_degree_iter ( G , nodes ) clusterc = { v : ( 0 if ( t == 0 ) else ( t / ( d * ( d - 1 ) ) ) ) for ( v , d , t , _ ) in td_iter } if ( nodes in G ) : return clusterc [ nodes ] return clusterc
compute the clustering coefficient for nodes .