Ask Your Question

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

asked 2017-03-04 20:40:53 +0200

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


how can I change to a string of the form



Thank you for any help.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2017-03-05 09:47:29 +0200

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)

Putting all together (and replacing the list with an iterator (by removing the brackets)) leads to:

sage: ''.join(str(i) for i in P)
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


Asked: 2017-03-04 20:40:53 +0200

Seen: 231 times

Last updated: Mar 05 '17