skbase.utils.unflatten#

skbase.utils.unflatten(obj, template)[source]#

Invert flattening given given template for nested list/tuple structure.

Converts an input list or tuple to a nested structure as provided in template while preserving the order of elements in the input.

Parameters:
objlist or tuple

The object to be unflattened.

templatenested list/tuple structure

Number of non-list/tuple elements of obj and template must be equal.

Returns:
list or tuple

Input coerced to have elements with nested list/tuples structure exactly as template and elements in sequence exactly as obj.

Examples

>>> from skbase.utils import unflatten
>>> unflatten([1, 2, 3, 4, 5, 6], [6, 3, [5, (2, 4)], 1])
[1, 2, [3, (4, 5)], 6]