flatten¶
- emlib.iterlib.flatten(s, exclude=(<class 'str'>, ), levels=inf)[source]¶
Return an iterator to the flattened items of sequence s
- Parameters:
s (
Iterable
[Union
[TypeVar
(T
),Iterable
[TypeVar
(T
)]]]) – the sequence to flattenexclude – classes to exclude from flattening
levels – how many levels to flatten
- Return type:
Iterator
[TypeVar
(T
)]- Returns:
the flattened version of s
Example
>>> seq = [1, [2, 3], [4, [5, 6]]] >>> list(flatten(seq)) [1, 2, 3, 4, 5, 6]