code: def _get_level_lengths(index, hidden_elements=None):
      """
      Given an index, find the level length for each element.
  
      Optional argument is a list of index positions which
      should not be visible.
  
      Result is a dictionary of (level, inital_position): span
      """
      sentinel = com.sentinel_factory()
      levels = index.format(
          sparsify=sentinel, adjoin=False, names=False
      )
  
      if hidden_elements is None:
          hidden_elements = []
  
      lengths = {}
      if index.nlevels == 1:
          for i, value in enumerate(levels):
              if i not in hidden_elements:
                  lengths[(0, i)] = 1
          return lengths
  
      for i, lvl in enumerate(levels):
          for j, row in enumerate(lvl):
              if not get_option("display.multi_sparse"):
                  lengths[(i, j)] = 1
              elif (row != sentinel) and (j not in hidden_elements):
                  last_label = j
                  lengths[(i, last_label)] = 1
              elif row != sentinel:
                  # even if its hidden, keep track of it in case
                  # length >1 and later elements are visible
                  last_label = j
                  lengths[(i, last_label)] = 0
              elif j not in hidden_elements:
                  lengths[(i, last_label)] += 1
  
      non_zero_lengths = {
          element: length
          for element, length in lengths.items()
          if length >= 1
      }
  
      return non_zero_lengths
  
imports: from collections import defaultdict
  from contextlib import contextmanager
  import copy
  from functools import partial
  from itertools import product
  from uuid import uuid1
  import numpy
  from pandas.compat import range
  from pandas.util._decorators import Appender
  from pandas.core.dtypes.common import is_float, is_string_like
  from pandas.core.dtypes.generic import ABCSeries
  import pandas
  from pandas.api.types import is_dict_like, is_list_like
  import pandas.core.common
  from pandas.core.config import get_option
  from pandas.core.generic import _shared_docs
  from pandas.core.indexing import _maybe_numeric_slice, _non_reducing_slice
label_desc: Use image node_id 3 for calling a global function with example usage: _get_level_lengths(index, hidden_elements) and returns: non_zero_lengths, lengths