code: def _min_cycle_basis(G, weight):
      cb = []
      # We  extract the edges not in a spanning tree. We do not really need a
      # *minimum* spanning tree. That is why we call the next function with
      # weight=None. Depending on implementation, it may be faster as well
      tree_edges = list(
          nx.minimum_spanning_edges(G, weight=None, data=False)
      )
      chords = G.edges - tree_edges - {(v, u) for u, v in tree_edges}
  
      # We maintain a set of vectors orthogonal to sofar found cycles
      set_orth = [{edge} for edge in chords]
      while set_orth:
          base = set_orth.pop()
          # kth cycle is "parallel" to kth vector in set_orth
          cycle_edges = _min_cycle(G, base, weight)
          cb.append([v for u, v in cycle_edges])
  
          # now update set_orth so that k+1,k+2... th elements are
          # orthogonal to the newly found cycle, as per [p. 336, 1]
          set_orth = [
              (
                  {
                      e
                      for e in orth
                      if e not in base
                      if e[::-1] not in base
                  }
                  | {
                      e
                      for e in base
                      if e not in orth
                      if e[::-1] not in orth
                  }
              )
              if sum(
                  (e in orth or e[::-1] in orth) for e in cycle_edges
              )
              % 2
              else orth
              for orth in set_orth
          ]
      return cb
  
imports: from collections import Counter, defaultdict
  from itertools import combinations, product
  from math import inf
  import networkx
  from networkx.utils import not_implemented_for, pairwise
label_desc: Use image node_id 12 for calling a global function with example usage: _min_cycle_basis(G, weight) and returns: cb