Processing math: 100%

First time here? Check out the FAQ!

Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

answered 0 years ago

dan_fulea gravatar image

Here is an alternative solution that explicitly uses the set X=1,2,,8 where the permutation is acting on, and a dictionary dic that passes from X to the letters. The dictionary is a replacement for the increment/decrement that converts between pythonic indexing and the natural set permutations act on...

letters = list('abcdefgh')
X = list(range(1, len(letters) + 1))
dic = dict( zip(X, letters) )

test_pi = Permutation((1,5,8,4), (2,6,7,3))
[dic[test_pi(x)] for x in X]

We obtain:

['e', 'b', 'c', 'a', 'h', 'f', 'g', 'd']
sage: ''.join(_)
'ebcahfgd'