code: def _iter_interleaved_items(self, elements):
          
          subtotals = self._subtotals
  
          for subtotal in subtotals.iter_for_anchor("top"):
              yield subtotal
  
          for element in elements:
              yield element
              for subtotal in subtotals.iter_for_anchor(element.element_id):
                  yield subtotal
  
          for subtotal in subtotals.iter_for_anchor("bottom"):
              yield subtotal
docs: Generate element or subtotal items in interleaved order.
  
          This ordering corresponds to how value "rows" (or columns) are to
          appear after subtotals have been inserted at their anchor locations.
          Where more than one subtotal is anchored to the same location, they
          appear in their document order in the cube response.
  
          Only elements in the passed *elements* collection appear, which
          allows control over whether missing elements are included by choosing
          `.all_elements` or `.valid_elements`.