code: def reverse_havel_hakimi_graph(aseq, bseq, create_using=None):
      """Returns a bipartite graph from two given degree sequences using a
      Havel-Hakimi style construction.
  
      The graph is composed of two partitions. Set A has nodes 0 to
      (len(aseq) - 1) and set B has nodes len(aseq) to (len(bseq) - 1).
      Nodes from set A are connected to nodes in the set B by connecting
      the highest degree nodes in set A to the lowest degree nodes in
      set B until all stubs are connected.
  
      Parameters
      ----------
      aseq : list
         Degree sequence for node set A.
      bseq : list
         Degree sequence for node set B.
      create_using : NetworkX graph instance, optional
         Return graph of this type.
  
      Notes
      -----
      The sum of the two sequences must be equal: sum(aseq)=sum(bseq)
      If no graph type is specified use MultiGraph with parallel edges.
      If you want a graph with no parallel edges use create_using=Graph()
      but then the resulting degree sequences might not be exact.
  
      The nodes are assigned the attribute 'bipartite' with the value 0 or 1
      to indicate which bipartite set the node belongs to.
  
      This function is not imported in the main namespace.
      To use it use nx.bipartite.reverse_havel_hakimi_graph
      """
      G = nx.empty_graph(0, create_using, default=nx.MultiGraph)
      if G.is_directed():
          raise nx.NetworkXError("Directed Graph not supported")
  
      # length of the each sequence
      lena = len(aseq)
      lenb = len(bseq)
      suma = sum(aseq)
      sumb = sum(bseq)
  
      if not suma == sumb:
          raise nx.NetworkXError(
              f"invalid degree sequences, sum(aseq)!=sum(bseq),{suma},{sumb}"
          )
  
      G = _add_nodes_with_bipartite_label(G, lena, lenb)
  
      if len(aseq) == 0 or max(aseq) == 0:
          return G  # done if no edges
  
      # build list of degree-repeated vertex numbers
      astubs = [[aseq[v], v] for v in range(lena)]
      bstubs = [[bseq[v - lena], v] for v in range(lena, lena + lenb)]
      astubs.sort()
      bstubs.sort()
      while astubs:
          (
              degree,
              u,
          ) = astubs.pop()  # take of largest degree node in the a set
          if degree == 0:
              break  # done, all are zero
          # connect the source to the smallest degree nodes in the b set
          for target in bstubs[0:degree]:
              v = target[1]
              G.add_edge(u, v)
              target[0] -= 1  # note this updates bstubs too.
              if target[0] == 0:
                  bstubs.remove(target)
  
      G.name = "bipartite_reverse_havel_hakimi_graph"
      return G
  
file_path: networkx/networkx/algorithms/bipartite/generators.py
imports: import math
  import numbers
  from functools import reduce
  import networkx
  from networkx.utils import nodes_or_number, py_random_state
label_desc: Use image node_id 4 for calling a global function with example usage: reverse_havel_hakimi_graph(aseq, bseq, create_using) and returns: G, G