code: def _neighbor_weights(nbrs, node2com):
      """Calculate weights between node and its neighbor communities.
  
      Parameters
      ----------
      nbrs : dictionary
             Dictionary with nodes' neighbors as keys and their edge weight as value.
      node2com : dictionary
             Dictionary with all graph's nodes as keys and their community index as value.
  
      """
      weights = defaultdict(float)
      for nbr, wt in nbrs.items():
          weights[node2com[nbr]] += wt
      return weights
  
file_path: networkx/networkx/algorithms/community/louvain.py
imports: from collections import defaultdict, deque
  import networkx
  from networkx.algorithms.community import modularity
  from networkx.utils import py_random_state
label_desc: Use image node_id 4 for calling a global function with example usage: _neighbor_weights(nbrs, node2com) and returns: weights