Recursively flatten `array` up to `depth` times. Args: array (list): List to flatten. depth (int, optional): Depth to flatten to. Defaults to ``1``. Returns: list: Flattened list. Example: >>> flatten_depth([[[1], [2, [3]], [[4]]]], 1)
(array, depth=1)
| 8 | yield item |
| 9 | |
| 10 | def flatten_depth(array, depth=1): |
| 11 | """ |
| 12 | Recursively flatten `array` up to `depth` times. |
| 13 | |
| 14 | Args: |
| 15 | array (list): List to flatten. |
| 16 | depth (int, optional): Depth to flatten to. Defaults to ``1``. |
| 17 | |
| 18 | Returns: |
| 19 | list: Flattened list. |
| 20 | |
| 21 | Example: |
| 22 | |
| 23 | >>> flatten_depth([[[1], [2, [3]], [[4]]]], 1) |
| 24 | [[1], [2, [3]], [[4]]] |
| 25 | >>> flatten_depth([[[1], [2, [3]], [[4]]]], 2) |
| 26 | [1, 2, [3], [4]] |
| 27 | >>> flatten_depth([[[1], [2, [3]], [[4]]]], 3) |
| 28 | [1, 2, 3, 4] |
| 29 | >>> flatten_depth([[[1], [2, [3]], [[4]]]], 4) |
| 30 | [1, 2, 3, 4] |
| 31 | |
| 32 | .. versionadded:: 4.0.0 |
| 33 | """ |
| 34 | return list(iterflatten(array, depth=depth)) |
| 35 | |
| 36 | def flatten(array): |
| 37 | """ |
no test coverage detected