def permutation_from_disjoint_cycles(cycles, offset=0):
    """Reconstruct a permutation image tuple from a list of disjoint cycles
    :param cycles: sequence of disjoint cycles
    :type cycles: list or tuple
    :param offset: Offset to subtract from the resulting permutation image points
    :type offset: int
    :return: permutation image tuple
    :rtype: tuple
    """
    perm_length = sum(map(len, cycles))
    res_perm = list(range(perm_length))
    for c in cycles:
        p1 = c[0] - offset
        for p2 in c[1:]:
            p2 = p2 - offset
            res_perm[p1] = p2
            p1 = p2
        res_perm[p1] = c[0] - offset #close cycle
    assert sorted(res_perm) == list(range(perm_length))
    return tuple(res_perm)
Reconstruct a permutation image tuple from a list of disjoint cycles
    :param cycles: sequence of disjoint cycles
    :type cycles: list or tuple
    :param offset: Offset to subtract from the resulting permutation image points
    :type offset: int
    :return: permutation image tuple
    :rtype: tuple