def flatten(x):
    """Returns the flattened list or tuple."""
    if len(x) == 0:
        return x
    if isinstance(x[0], list) or isinstance(x[0], tuple):
        return flatten(x[0]) + flatten(x[1:])
    return x[:1] + flatten(x[1:])