flatten_list

flatten_list(values)

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

Name Type Description Default
values Iterable[Any] An iterable object (except strings and bytes) that may contain nested iterables of arbitrary depth. required

Returns

Name Type Description
list[Any] A flattened list containing all elements from values.

Raises

Name Type Description
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([])
[]