def permut(liste):
    P 	= [ 5, 9, 3, 6, 1, 4, 2, 7, 8]
    result 	= [ ]
    for i in P:
        result.append( liste[ i-1 ] )
    return result

def sigma(E, n):
    result = E
    for i in range(n):
        result = permut(result)
    return result

E = [1,2,3,4,5,6,7,8,9]
F = [1,2,3,4,5,6,7,8,9]
id , n = False , 0
while id == False:
    n += 1
    F = sigma( F , 1 )
    if F == E:
        id = True

print(n)

def cycle_to_permut(cycle,n):
    E = list(range(1,n+1))
    eFinal = E[cycle[0]-1]
    for i in range(len(cycle)-1):
        E[cycle[i]-1]=E[cycle[i+1]-1]

    E[ cycle[-1] - 1 ] = eFinal
    return E

def permut(liste,p):
    result 	= [ ]
    for i in p:
        result.append( liste[ i-1 ] )

    return result

def image(sigma,tau,n):
    E = range(1,n+1)
    t = cycle_to_permut(tau,n)
    s = cycle_to_permut(sigma,n)
    R = permut( permut(E,t) , s)
    return R

sigma , tau = (1,3,4,5,8,6) , (2,7)
print( image(sigma,tau,8) )
