flatten_list()

audeer.flatten_list(nested_list)[source]

Flatten an arbitrarily nested list.

Implemented without recursion to avoid stack overflows. Returns a new list, the original list is unchanged.

Parameters

nested_list (List) – nested list

Return type

List

Returns

flattened list

Examples

>>> flatten_list([1, 2, 3, [4], [], [[[[[[[[[5]]]]]]]]]])
[1, 2, 3, 4, 5]
>>> flatten_list([[1, 2], 3])
[1, 2, 3]