apply Permutation to a letters list

asked 2024-11-19 16:44:05 +0100

ortollj gravatar image

Hi

Sorry for this very basic question, but how to apply the Permutation function to a list of letters ? I think it should exist a simplest way than the the cooking below. I searched the web, without success !

def applyGen(ge,dic) :   
    return [ge[dic.get(e)] for e in dic.keys() ]

def decrement_dic(dic): 
    return {k - 1: v - 1 for k, v in dic.items()} 

lettersL=['a','b','c','d','e','f','g','h']

test=Permutation((1,5,8,4),(2,6,7,3))
dicD=decrement_dic(test.dict())
applyGen(lettersL,dicD)
edit retag flag offensive close merge delete

Comments

1

Like this

sage: L = ['a','b','c','d','e','f','g','h']
sage: test = Permutation((1,5,8,4),(2,6,7,3))
sage: [L[test(i + 1) - 1] for i in range(len(L))]
['e', 'b', 'c', 'a', 'h', 'f', 'g', 'd']

Note that Python numbering starts from 0.

FrédéricC gravatar imageFrédéricC ( 2024-11-19 17:17:37 +0100 )edit

ok thank you @FrédéricC

ortollj gravatar imageortollj ( 2024-11-19 18:26:40 +0100 )edit