Unpacking nested lists of indefinite depth

Here i just try to find the best solution for this task

Functions describes

Examples of python realization of solution for unpacking lists with indefinite depth

unpacking_flatten_lists.funcs.niccolum_flatten(array: Iterable[T_co]) → List[T][source]

Non recursive algorithm Based on pop/insert elements in current list

unpacking_flatten_lists.funcs.outer_flatten_1(array: Iterable[T_co]) → List[T][source]

Based on C realization of this solution More on:

https://iteration-utilities.readthedocs.io/en/latest/generated/deepflatten.html

https://github.com/MSeifert04/iteration_utilities/blob/384948b4e82e41de47fa79fb73efc56c08549b01/src/deepflatten.c

unpacking_flatten_lists.funcs.outer_flatten_2(array: Iterable[T_co]) → List[T][source]

recursive algorithm, vaguely reminiscent of recursion_flatten. Based on next pattern:

try:
    tree = iter(node)
except TypeError:
    yield node

more on: https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.collapse

unpacking_flatten_lists.funcs.recursive_flatten_generator(array: Iterable[T_co]) → List[T][source]

Recursive algorithm Looks like recursive_flatten_iterator, but with extend/append

unpacking_flatten_lists.funcs.recursive_flatten_iterator(arr: Iterable[T_co]) → Iterator[T_co][source]

Recursive algorithm based on iterator Usual solution to this problem

unpacking_flatten_lists.funcs.tishka_flatten(data: Iterable[T_co]) → List[T][source]

Non recursive algorithm Based on append/extend elements to new list

unpacking_flatten_lists.funcs.tishka_flatten_with_stack(seq: Iterable[T_co]) → List[T][source]

Non recursive algorithm Based on zart_flatten, but build on try/except pattern

unpacking_flatten_lists.funcs.zart_flatten(a: Iterable[T_co]) → List[T][source]

Non recursive algorithm Based on pop from old and append elements to new list

Data describes

unpacking_flatten_lists.data.create_data_decreasing_depth(data: Union[List[T], Iterator[T_co]], length: int, max_depth: int, _current_depth: int = None, _result: List[T] = None) → List[T][source]

creates data in depth on decreasing.

Examples:

>>> data = create_data_decreasing_depth(list(range(1, 11)), length=5, max_depth=3)
>>> assert data == [[[1, 2, 3, 4, 5], 6, 7, 8, 9, 10]]
>>> data = create_data_decreasing_depth(list(range(1, 11)), length=2, max_depth=3)
>>> assert data == [[[1, 2], 3, 4], 5, 6], [[7, 8,] 9, 10]]
unpacking_flatten_lists.data.create_data_increasing_depth(data: Union[List[T], Iterator[T_co]], length: int, max_depth: int, _current_depth: int = None, _result: List[T] = None) → List[T][source]

creates data in depth to increase.

Examples:

>>> data = create_data_increasing_depth(list(range(1, 11)), length=5, max_depth=3)
>>> assert data == [1, 2, 3, 4, 5, [6, 7, 8, 9, 10]]
>>> data = create_data_increasing_depth(list(range(1, 11)), length=2, max_depth=3)
>>> assert data == [1, 2, [3, 4, [5, 6]]], 7, 8, [9, 10]]
unpacking_flatten_lists.data.generate_data() → List[Tuple[str, Dict[str, Union[range, int, float]]]][source]

Generated collections of Data by pattern

{amount_item}_amount_{length}_length_{max_depth}_max_depth

where:

amount_item:

len of flatten elements

length:

len of elements at the same level of nesting

max_depth:

highest possible level of nesting