from itertools import permutations s=input() permutation=[' '.join(p) for p in permutations(s)] print(str(permutation)); code example
Example: python all permutations of a string
>>> from itertools import permutations
>>> perms = [''.join(p) for p in permutations('stack')]
>>> perms