+ 1
Python
Code: from itertools import permutations a = input() perms = [''.join(p) for p in permutations(a)] print(perms) Output 1 ['abc', 'acb', 'bac', 'bca', 'cab', 'cba'] Output 2 abc acb bac bca cab cba How can i make changes to my code so that the program can convert the output from Output 1 to Output 2 ?
4 Answers
+ 5
Try this:
print(*perms, sep='\n')
Here * is used as the unpacking operator to pull out the list elements separately. Then sep='\n' tells print how to separate the elements while printing - in this case using a newline.
+ 5
Levy ,
we can create the output without using a table.
from itertools import permutations
a = input()
for item in permutations(a):
print(''.join(item))
+ 1
Brian Works for me too. Thanks
0
Yeah, it works. Thanks