code: def _margins(
      vars: tuple[list[str], list[str]],
      margins: bool | list[str] = True,
  ):
      """
      Figure out margining variables.
  
      Given the variables that form the rows and
      columns, and a set of desired margins, works
      out which ones are possible. Variables that
      can't be margined over are dropped silently.
  
      Parameters
      ----------
      vars : list
          variable names for rows and columns
      margins : bool | list
          If true, margins over all vars, otherwise
          only those listed
  
      Return
      ------
      out : list
          All the margins to create.
      """
      if margins is False:
          return []
  
      def fn(_vars):
          "The margin variables for a given row or column"
          # The first item is and empty list for no margins
          dim_margins = [[]]
          # for each wanted variable, couple it with
          # all variables to the right
          for i, u in enumerate(_vars):
              if margins is True or u in margins:
                  lst = [u] + list(_vars[i + 1 :])
                  dim_margins.append(lst)
          return dim_margins
  
      # Margin variables for rows and columns
      row_margins = fn(vars[0])
      col_margins = fn(vars[1])
  
      # Cross the two
      lst = list(itertools.product(col_margins, row_margins))
  
      # Clean up -- merge the row and column variables
      pretty = []
      for c, r in lst:
          pretty.append(r + c)
      return pretty
  
imports: from __future__ import annotations
  import inspect
  import itertools
  import warnings
  from collections import defaultdict
  from collections.abc import Iterable, Sequence
  from contextlib import suppress
  from typing import TYPE_CHECKING, cast, overload
  from warnings import warn
  import numpy
  import pandas
  from pandas.core.groupby import DataFrameGroupBy
  from ..exceptions import PlotnineError, PlotnineWarning
  from ..mapping import aes
label_desc: Use image node_id 6 for calling a global function with example usage: _margins(vars, margins) and returns: pretty, list, dim_margins