import itertools


def is_valid_permutation(in_perm, for_labels=True):
    """
    A permutation in generalised Cauchy notation is a list of 2 lists of same size:
    a = [[1,2,3], [2,3,1]]
    means permute 1 with 2, 2 with 3, 3 with 1.
    :param for_labels: if True the permutation elements must be int.
    :param in_perm: input permutation.
    """
    if not len(in_perm) == 2:
        return False
    if not len(in_perm[0]) == len(in_perm[1]) == len(set(in_perm[0])) == len(set(in_perm[1])):
        return False
    if not (sorted(set(in_perm[0])) > sorted(set(in_perm[1])))-(sorted(set(in_perm[0])) < sorted(set(in_perm[1]))) == 0:
        return False
    if for_labels:
        # as dealing with labels, all the elements must be int
        if not all(isinstance(x, int) for x in list(itertools.chain(*in_perm))):
            return False
    return True