code: def _triangles_and_degree_iter(G, nodes=None):
      """Return an iterator of (node, degree, triangles, generalized degree).
  
      This double counts triangles so you may want to divide by 2.
      See degree(), triangles() and generalized_degree() for definitions
      and details.
  
      """
      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)
  
file_path: networkx/networkx/algorithms/cluster.py
imports: from collections import Counter
  from itertools import chain, combinations
  import networkx
  from networkx.utils import not_implemented_for
label_desc: Use image node_id 2 for calling a global function with example usage: _triangles_and_degree_iter(G, nodes) without return types