apply Permutation cycles to a letters list second episode
Hi
seeapply Permutation cycles to a letters list
I do not understand why there are errors when G.list() is used for tuples permutation cycles list:
import string
import sage.combinat.permutation as permutation
# apply each permutation cycle from tuples list to hL=['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']
def applyCyclesToLetters(tuplesL,hL) :
GL=[]
firstL=[]
for t in tuplesL :
try :
test=permutation.from_cycles(len(hL),t)
GL.append([hL[test[i] - 1] for i in range(len(hL))])
firstL.append(GL[-1][0]) # append only the first element of the permutation
except Exception as e:
print('error ',t,e)
return GL # ,firstL
hL=list(string.ascii_lowercase[0:8])
G = PermutationGroup([(1,2,3),(7,8)])
verticesL=[]
for el in G.list():
verticesL.append(tuple(el))
verticesL
# verticesCopyL is copy paste of print (verticeL) , then it is ok for applyCyclesToLetters(verticesCopyL,hL)
verticesCopyL=[(), ((7,8),), ((1,3,2),), ((1,3,2), (7,8)), ((1,2,3),), ((1,2,3), (7,8))]
print('verticesL : ')
print(verticesL)
print('verticesCopyL : ')
print(verticesCopyL)
print('applyCyclesToLetters(verticesCopyL)')
print(applyCyclesToLetters(verticesCopyL,hL))
print('applyCyclesToLetters(verticesL)')
print(applyCyclesToLetters(verticesL,hL))
print(type(verticesCopyL),[type(el) for el in verticesCopyL])
print(type(verticesL),[type(el) for el in verticesL])