UniCoreFW

flatten_depth()

Recursively flattens array up to the specified depth.

Implementation

Args: array: List to flatten. depth: How deep to flatten the array. Returns: Flattened list.

Example

flatten_depth([[1], [2, [3]], [[4]]], 2)

Expected output: [1, 2, 3, [4]]

Source Code

def flatten_depth(array: Any, depth: int = 1) -> List[Any]: return flatten(array, depth)