Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

I propose to improve @Frédéric's solution as below to avoid errors in certain cases :

tuplesL=[ ((1,5,8,4),(2,6,7,3)), ((4,5)),((1,2,3)),((1,2,3),(4,5)),((1,2,3),(4,5),(7,8))]
for t in tuplesL :
    print('permutation tuples= ',t)
    try :
        test=Permutation(t)
        print('FredericC solution OK : ',[L[test(i + 1) - 1] for i in range(len(L))])
    except :
        print('error from FredericC solution')
    P=Permutation(t)
    Pletters= [L[P(i + 1) - 1] for i in range(len(P.dict()))] +[L[i] for i in range(len(P.dict()),len(L))]
    print(Pletters)

But unfortunately this solution does not allow singletons in list of tuples ! like Wolfram alpha do

I propose to improve @Frédéric's @FrédéricC's solution as below to avoid errors in certain cases :

tuplesL=[ ((1,5,8,4),(2,6,7,3)), ((4,5)),((1,2,3)),((1,2,3),(4,5)),((1,2,3),(4,5),(7,8))]
for t in tuplesL :
    print('permutation tuples= ',t)
    try :
        test=Permutation(t)
        print('FredericC solution OK : ',[L[test(i + 1) - 1] for i in range(len(L))])
    except :
        print('error from FredericC solution')
    P=Permutation(t)
    Pletters= [L[P(i + 1) - 1] for i in range(len(P.dict()))] +[L[i] for i in range(len(P.dict()),len(L))]
    print(Pletters)

But unfortunately this solution does not allow singletons in list of tuples ! like Wolfram alpha do