Ask Your Question

Revision history [back]

I think this code should work: first construct a list with the one-line form for the permutation, then convert it to a permutation:

def find_permutation(L1, L2):
    oneline = []
    for n in L1:
        # Look for n in L2.
        # Sage's one-line permutation format expects indices to start at 1, not 0,
        # so add 1 to all indices here.
        j = L2.index(n) + 1
        # If we've already found this instance, look in the rest of the list for another one.
        while j in oneline:
            j += L2[j:].index(n) + 1
        oneline.append(j)
    return oneline

Permutation(find_permutation(L1, L2))