flatten_list
Flatten a nested iterable into a single, one-dimensional list.
This function takes an iterable that may contain nested iterables and returns a new list with all elements flattened into a single level.
Parameters
| values |
Iterable[Any] |
An iterable object (except strings and bytes) that may contain nested iterables of arbitrary depth. |
required |
Returns
|
list[Any] |
A flattened list containing all elements from values. |
Raises
|
TypeError |
If values is not an iterable or if it is a string/bytes object. |
Examples
>>> flatten_list([1, 2, [3, 4]])
[1, 2, 3, 4]
>>> flatten_list([[1, 2], [3, [4, 5]]])
[1, 2, 3, 4, 5]
>>> flatten_list([])
[]