code: def getitem(lst, indices):
      
      if not indices:
          return lst
  
      i, indices = indices[0], indices[1:]
      item = list.__getitem__(lst, i)
  
      if isinstance(i, int):
          return getitem(item, indices)
  
      # Empty slice: check if all subsequent indices are in range for the
      # full slice, raise IndexError otherwise. This is NumPy's behavior.
      if not item:
          if lst:
             _ = getitem(lst, (slice(None),) + indices)
          elif any(isinstance(k, int) for k in indices):
             raise IndexError
          return []
  
      return [getitem(x, indices) for x in item]
docs: Definition for multidimensional slicing and indexing on arbitrarily
         shaped nested lists.