MCPcopy
hub / github.com/omkarcloud/botasaurus / flatten_depth

Function flatten_depth

botasaurus/list_utils.py:10–34  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

8 yield item
9
10def 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
36def flatten(array):
37 """

Callers 2

flattenFunction · 0.85
flatten_deepFunction · 0.85

Calls 1

iterflattenFunction · 0.85

Tested by

no test coverage detected