code: def unflatten(obj, template):
      """Invert flattening, given template for nested list/tuple structure.
  
      Parameters
      ----------
      obj : list or tuple of elements
      template : nested list/tuple structure
          number of non-list/tuple elements of obj and template must be equal
  
      Returns
      -------
      rest : list or tuple of elements
          has element bracketing exactly as `template`
              and elements in sequence exactly as `obj`
  
      Example
      -------
      >>> unflatten([1, 2, 3, 4, 5, 6], [6, 3, [5, (2, 4)], 1])
      [1, 2, [3, (4, 5)], 6]
      """
      if not isinstance(template, (list, tuple)):
          return obj[0]
  
      list_or_tuple = type(template)
      ls = [unflat_len(x) for x in template]
      for i in range(1, len(ls)):
          ls[i] += ls[i - 1]
      ls = [0] + ls
  
      res = [
          unflatten(obj[ls[i] : ls[i + 1]], template[i])
          for i in range(len(ls) - 1)
      ]
  
      return list_or_tuple(res)
  
imports: from inspect import isclass
  import numpy
  import pandas
  from sktime.base import BaseEstimator
label_desc: Use image node_id 2 for calling a global function with example usage: unflatten(obj, template) and returns: list_or_tuple, obj