Python Practice › String Programs › Program 91
Permutations of a string
Write a Python program to list all permutations of a string with a built-in function.
Input
"CDE"
Output
['CDE', 'CED', 'DCE', 'DEC', 'ECD', 'EDC']
Approach
itertools.permutationsand join each tuple.
Solution
from itertools import permutationsprint(["".join(p) for p in permutations("CDE")])Output
['CDE', 'CED', 'DCE', 'DEC', 'ECD', 'EDC']
Learn the concept
New to this topic? Read the lesson, then come back.