RAIMAD

Function flatten from raimad.iters

def flatten(iterable: collections.abc.Iterable[typing.Any]) -> collections.abc.Iterable[typing.Any]
Recursively flatten a nested iterable.
Click to show code
def flatten(iterable: Iterable[Any]) -> Iterable[Any]:
    """Recursively flatten a nested iterable."""
    if not isinstance(iterable, Iterable) or isinstance(iterable, str):
        # This terminates the recursion
        return [iterable]

    return [
        item
        for sub in iterable
        for item in flatten(sub)
        ]