code: def inter_community_edges(G, partition):
      """Returns the number of inter-community edges for a partition of `G`.
      according to the given
      partition of the nodes of `G`.
  
      Parameters
      ----------
      G : NetworkX graph.
  
      partition : iterable of sets of nodes
          This must be a partition of the nodes of `G`.
  
      The *inter-community edges* are those edges joining a pair of nodes
      in different blocks of the partition.
  
      Implementation note: this function creates an intermediate graph
      that may require the same amount of memory as that of `G`.
  
      """
      # Alternate implementation that does not require constructing a new
      # graph object (but does require constructing an affiliation
      # dictionary):
      #
      #     aff = dict(chain.from_iterable(((v, block) for v in block)
      #                                    for block in partition))
      #     return sum(1 for u, v in G.edges() if aff[u] != aff[v])
      #
      MG = nx.MultiDiGraph if G.is_directed() else nx.MultiGraph
      return nx.quotient_graph(G, partition, create_using=MG).size()
  
file_path: networkx/networkx/algorithms/community/quality.py
imports: from itertools import combinations
  import networkx
  from networkx import NetworkXError
  from networkx.algorithms.community.community_utils import is_partition
  from networkx.utils.decorators import argmap
label_desc: Use image node_id 3 for calling a global function with example usage: inter_community_edges(G, partition) and returns: nx