code: def _create_grid(
      iterable: Iterable[UIElement | list[UIElement]],
      sizing_mode: SizingModeType | None,
      layer: int = 0,
      **kwargs,
  ) -> Row | Column:
      """Recursively create grid from input lists."""
      return_list: list[UIElement] = []
      for item in iterable:
          if isinstance(item, list):
              return_list.append(
                  _create_grid(item, sizing_mode, layer + 1)
              )
          elif isinstance(item, LayoutDOM):
              if sizing_mode is not None and _has_auto_sizing(item):
                  item.sizing_mode = sizing_mode
              return_list.append(item)
          elif isinstance(item, UIElement):
              return_list.append(item)
          else:
              raise ValueError(
                  f"""Only LayoutDOM items can be inserted into a layout.
                  Tried to insert: {item} of type {type(item)}""",
              )
      if layer % 2 == 0:
          return column(
              children=return_list, sizing_mode=sizing_mode, **kwargs
          )
      else:
          return row(
              children=return_list, sizing_mode=sizing_mode, **kwargs
          )
  
imports: from __future__ import annotations
  import logging
  import math
  from collections import defaultdict
  from typing import TYPE_CHECKING, Any, Callable, Iterable, Iterator, Literal, Sequence, TypeVar, Union, overload
  from .core.enums import Location, LocationType, SizingModeType
  from .core.property.singletons import Undefined, UndefinedType
  from .models import Column, CopyTool, ExamineTool, FlexBox, FullscreenTool, GridBox, GridPlot, LayoutDOM, Plot, Row, SaveTool, Spacer, Tool, Toolbar, ToolProxy, UIElement
  from .util.dataclasses import dataclass
  from .util.warnings import warn
label_desc: Use image node_id 20 for calling a global function with example usage: _create_grid(iterable, sizing_mode, layer) and returns: column, row