code: def _reconstruct_k_components(k_comps):
      result = {}
      max_k = max(k_comps)
      for k in reversed(range(1, max_k + 1)):
          if k == max_k:
              result[k] = list(_consolidate(k_comps[k], k))
          elif k not in k_comps:
              result[k] = list(_consolidate(result[k + 1], k))
          else:
              nodes_at_k = set.union(*k_comps[k])
              to_add = [
                  c
                  for c in result[k + 1]
                  if any(n not in nodes_at_k for n in c)
              ]
              if to_add:
                  result[k] = list(_consolidate(k_comps[k] + to_add, k))
              else:
                  result[k] = list(_consolidate(k_comps[k], k))
      return result
  
file_path: networkx/networkx/algorithms/connectivity/kcomponents.py
imports: from collections import defaultdict
  from itertools import combinations
  from operator import itemgetter
  import networkx
  from networkx.algorithms.flow import edmonds_karp
  from networkx.utils import not_implemented_for
label_desc: Use image node_id 4 for calling a global function with example usage: _reconstruct_k_components(k_comps) and returns: result