ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sun, 05 Mar 2017 02:47:29 -0600Changing a 1-line permutation to a string 'blablabla'http://ask.sagemath.org/question/36828/changing-a-1-line-permutation-to-a-string-blablabla/ Hello, guys. First of all I'm very new to Sage, and also this forum, so please be generous to my question..
So, I was wondering given a permutation, say
Permutation([1,2,3,4])
how can I change to a string of the form
'1234'
??
Thank you for any help.Sat, 04 Mar 2017 13:40:53 -0600http://ask.sagemath.org/question/36828/changing-a-1-line-permutation-to-a-string-blablabla/Answer by tmonteil for <p>Hello, guys. First of all I'm very new to Sage, and also this forum, so please be generous to my question..</p>
<p>So, I was wondering given a permutation, say</p>
<p>Permutation([1,2,3,4])</p>
<p>how can I change to a string of the form</p>
<p>'1234'</p>
<p>??</p>
<p>Thank you for any help.</p>
http://ask.sagemath.org/question/36828/changing-a-1-line-permutation-to-a-string-blablabla/?answer=36832#post-id-36832First, you can get the list of values of P, viewed as strings as follows:
sage: sage: L = [str(i) for i in P]
sage: L
['1', '2', '3', '4']
Then you can join those strings with an empty separator:
sage: ''.join(L)
'1234'
Putting all together (and replacing the list with an iterator (by removing the brackets)) leads to:
sage: ''.join(str(i) for i in P)
'1234'
Sun, 05 Mar 2017 02:47:29 -0600http://ask.sagemath.org/question/36828/changing-a-1-line-permutation-to-a-string-blablabla/?answer=36832#post-id-36832