code: def allcombinations(A, B, ordered):
      """
      Restructure A and B to have the same number of elements.
  
      Parameters
      ==========
  
      ordered must be either 'commutative' or 'associative'.
  
      A and B can be rearranged so that the larger of the two lists is
      reorganized into smaller sublists.
  
      Examples
      ========
  
      >>> from sympy.unify.core import allcombinations
      >>> for x in allcombinations((1, 2, 3), (5, 6), 'associative'): print(x)
      (((1,), (2, 3)), ((5,), (6,)))
      (((1, 2), (3,)), ((5,), (6,)))
  
      >>> for x in allcombinations((1, 2, 3), (5, 6), 'commutative'): print(x)
          (((1,), (2, 3)), ((5,), (6,)))
          (((1, 2), (3,)), ((5,), (6,)))
          (((1,), (3, 2)), ((5,), (6,)))
          (((1, 3), (2,)), ((5,), (6,)))
          (((2,), (1, 3)), ((5,), (6,)))
          (((2, 1), (3,)), ((5,), (6,)))
          (((2,), (3, 1)), ((5,), (6,)))
          (((2, 3), (1,)), ((5,), (6,)))
          (((3,), (1, 2)), ((5,), (6,)))
          (((3, 1), (2,)), ((5,), (6,)))
          (((3,), (2, 1)), ((5,), (6,)))
          (((3, 2), (1,)), ((5,), (6,)))
      """
  
      if ordered == "commutative":
          ordered = 11
      if ordered == "associative":
          ordered = None
      sm, bg = (A, B) if len(A) < len(B) else (B, A)
      for part in kbins(list(range(len(bg))), len(sm), ordered=ordered):
          if bg == B:
              yield tuple((a,) for a in A), partition(B, part)
          else:
              yield partition(A, part), tuple((b,) for b in B)
  
imports: from sympy.utilities.iterables import kbins
label_desc: Use image node_id 7 for calling a global function with example usage: allcombinations(A, B, ordered) without return types