def flatten(seq, container=list):
    """
    >>> list(flatten([1]))
    [1]
    >>> list(flatten([[1, 2], [1, 2]]))
    [1, 2, 1, 2]
    >>> list(flatten([[[1], [2]], [[1], [2]]]))
    [1, 2, 1, 2]
    >>> list(flatten(((1, 2), (1, 2)))) # Don't flatten tuples
    [(1, 2), (1, 2)]
    >>> list(flatten((1, 2, [3, 4]))) # support heterogeneous
    [1, 2, 3, 4]
    """
    if isinstance(seq, str):
        yield seq
    else:
        for item in seq:
            if isinstance(item, container):
                yield from flatten(item, container=container)
            else:
                yield item

    >>> list(flatten([1]))
    [1]
    >>> list(flatten([[1, 2], [1, 2]]))
    [1, 2, 1, 2]
    >>> list(flatten([[[1], [2]], [[1], [2]]]))
    [1, 2, 1, 2]
    >>> list(flatten(((1, 2), (1, 2)))) # Don't flatten tuples
    [(1, 2), (1, 2)]
    >>> list(flatten((1, 2, [3, 4]))) # support heterogeneous
    [1, 2, 3, 4]
    
src/flash/core/serve/dag/task.py