Ask Your Question
1

Changing a 1-line permutation to a string 'blablabla'

asked 2017-03-04 13:40:53 -0500

this post is marked as community wiki

This post is a wiki. Anyone with karma >750 is welcome to improve it.

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.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2017-03-05 02:47:29 -0500

tmonteil gravatar image

First, 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'
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2017-03-04 13:40:53 -0500

Seen: 28 times

Last updated: Mar 05