def flatten(seq):
    """
    Flatten a sequence of sequences and items.

    Args:
        seq (list | tuple): The sequence to be flattened.

    Returns:
        list | tuple: The flattened sequence.
    """
    seq_type = type(seq)

    out = []
    for item in seq:
        if isinstance(item, (list, tuple)):
            out += flatten(item)
        else:
            out.append(item)

    return seq_type(out)