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

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