def flatten_tuple(x):
    """ Flatten nested tuples """
    if type(x) is not tuple:
        return x
    x_len = len(x)
    i = 0
    while i < x_len:
        if type(x[i]) is tuple:
            x_len += len(x[i]) - 1
            x = x[:i] + x[i] + x[i + 1:]
        else:
            i += 1
    return x
