@not_implemented_for('multigraph')
def _triangles_and_degree_iter(G, nodes=None):
 if (nodes is None):
  nodes_nbrs = G.adj.items()
 else:
  nodes_nbrs = ((n, G[n]) for n in G.nbunch_iter(nodes))
 for (v, v_nbrs) in nodes_nbrs:
  vs = (set(v_nbrs) - {v})
  gen_degree = Counter([len((vs & (set(G[w]) - {w}))) for w in vs])
  ntriangles = sum([(k * val) for (k, val) in gen_degree.items()])
  (yield (v, len(vs), ntriangles, gen_degree))

@ not_implemented_for ( 'multigraph' ) def _triangles_and_degree_iter ( G , nodes = None ) : if ( nodes is None ) : nodes_nbrs = G . adj . items ( ) else : nodes_nbrs = ( ( n , G [ n ] ) for n in G . nbunch_iter ( nodes ) ) for ( v , v_nbrs ) in nodes_nbrs : vs = ( set ( v_nbrs ) - { v } ) gen_degree = Counter ( [ len ( ( vs & ( set ( G [ w ] ) - { w } ) ) ) for w in vs ] ) ntriangles = sum ( [ ( k * val ) for ( k , val ) in gen_degree . items ( ) ] ) ( yield ( v , len ( vs ) , ntriangles , gen_degree ) )
return an iterator of .