code: def _fast_label_count(G, comms, node, weight=None):
      """Computes the frequency of labels in the neighborhood of a node.
  
      Returns a dictionary keyed by label to the frequency of that label.
      """
  
      if weight is None:
          # Unweighted (un)directed simple graph.
          if not G.is_multigraph():
              label_freqs = Counter(
                  map(comms.get, nx.all_neighbors(G, node))
              )
  
          # Unweighted (un)directed multigraph.
          else:
              label_freqs = defaultdict(int)
              for nbr in G[node]:
                  label_freqs[comms[nbr]] += len(G[node][nbr])
  
              if G.is_directed():
                  for nbr in G.pred[node]:
                      label_freqs[comms[nbr]] += len(G.pred[node][nbr])
  
      else:
          # Weighted undirected simple/multigraph.
          label_freqs = defaultdict(float)
          for _, nbr, w in G.edges(node, data=weight, default=1):
              label_freqs[comms[nbr]] += w
  
          # Weighted directed simple/multigraph.
          if G.is_directed():
              for nbr, _, w in G.in_edges(node, data=weight, default=1):
                  label_freqs[comms[nbr]] += w
  
      return label_freqs
  
file_path: networkx/networkx/algorithms/community/label_propagation.py
imports: from collections import Counter, defaultdict, deque
  import networkx
  from networkx.utils import groups, not_implemented_for, py_random_state
label_desc: Use image node_id 2 for calling a global function with example usage: _fast_label_count(G, comms, node, weight) and returns: label_freqs