def flatten(iterable, types=(tuple, list), initial=None):
    """Collapse nested iterables into one flat :class:`list`.

    Args:
        iterable:
            Nested container.
        types:
            Type(s) to be collapsed. This argument is passed directly to
            :func:`isinstance`.
        initial:
            A pre-existing :class:`list` to append to. An empty list is created
            if one is not supplied.

    Returns:
        list: The flattened output.

    ::

        >>> flatten([[1, 2], 3, [4, [5]]])
        [1, 2, 3, 4, 5]
        >>> flatten(1.0)
        [1.0]
        >>> flatten([(1, 2), 3, (4, 5)])
        [1, 2, 3, 4, 5]
        >>> flatten([(1, 2), 3, (4, 5)], types=list)
        [(1, 2), 3, (4, 5)]
        >>> flatten([(1, 2), 3, (4, 5)], initial=[6, 7])
        [6, 7, 1, 2, 3, 4, 5]

    """
    if initial is None:
        initial = []
    if isinstance(iterable, types):
        for i in iterable:
            flatten(i, types, initial)
    else:
        initial.append(iterable)
    return initial