Python Practice › String Programs › Program 91

Permutations of a string

EasyString Programs · 91 of 106

Write a Python program to list all permutations of a string with a built-in function.

Advertisement
Input
"CDE"
Output
['CDE', 'CED', 'DCE', 'DEC', 'ECD', 'EDC']

Approach

  1. itertools.permutations and join each tuple.

Solution

Python
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.

More string programs

← All 106 String Programs

Leave a Comment