code: def generalized_degree(G, nodes=None):
      r"""Compute the generalized degree for nodes.
  
      For each node, the generalized degree shows how many edges of given
      triangle multiplicity the node is connected to. The triangle multiplicity
      of an edge is the number of triangles an edge participates in. The
      generalized degree of node :math:`i` can be written as a vector
      :math:`\mathbf{k}_i=(k_i^{(0)}, \dotsc, k_i^{(N-2)})` where
      :math:`k_i^{(j)}` is the number of edges attached to node :math:`i` that
      participate in :math:`j` triangles.
  
      Parameters
      ----------
      G : graph
  
      nodes : container of nodes, optional (default=all nodes in G)
         Compute the generalized degree for nodes in this container.
  
      Returns
      -------
      out : Counter, or dictionary of Counters
         Generalized degree of specified nodes. The Counter is keyed by edge
         triangle multiplicity.
  
      Examples
      --------
      >>> G = nx.complete_graph(5)
      >>> print(nx.generalized_degree(G, 0))
      Counter({3: 4})
      >>> print(nx.generalized_degree(G))
      {0: Counter({3: 4}), 1: Counter({3: 4}), 2: Counter({3: 4}), 3: Counter({3: 4}), 4: Counter({3: 4})}
  
      To recover the number of triangles attached to a node:
  
      >>> k1 = nx.generalized_degree(G, 0)
      >>> sum([k * v for k, v in k1.items()]) / 2 == nx.triangles(G, 0)
      True
  
      Notes
      -----
      In a network of N nodes, the highest triangle multiplicity an edge can have
      is N-2.
  
      The return value does not include a `zero` entry if no edges of a
      particular triangle multiplicity are present.
  
      The number of triangles node :math:`i` is attached to can be recovered from
      the generalized degree :math:`\mathbf{k}_i=(k_i^{(0)}, \dotsc,
      k_i^{(N-2)})` by :math:`(k_i^{(1)}+2k_i^{(2)}+\dotsc +(N-2)k_i^{(N-2)})/2`.
  
      References
      ----------
      .. [1] Networks with arbitrary edge multiplicities by V. Zlatić,
          D. Garlaschelli and G. Caldarelli, EPL (Europhysics Letters),
          Volume 97, Number 2 (2012).
          https://iopscience.iop.org/article/10.1209/0295-5075/97/28005
      """
      if nodes in G:
          return next(_triangles_and_degree_iter(G, nodes))[3]
      return {
          v: gd for v, d, t, gd in _triangles_and_degree_iter(G, nodes)
      }
  
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 10 for calling a global function with example usage: generalized_degree(G, nodes) and returns: unknown, next