Python Program to Find All the Permutations of a String Using itertools
# Compute all the Permutation of the String Using itertools in Python
from itertools import permutations
# Initialising string
ini_str = "hello"
# Printing initial string
print("Initial string", ini_str)
# Finding all permutation
permutation = [''.join(p) for p in permutations(ini_str)]
# Printing result
print("Resultant List", str(permutation))
Output:
Initial string hello
Resultant List ['hello', 'helol', 'hello', 'helol', 'heoll', 'heoll', 'hlelo', 'hleol', 'hlleo', 'hlloe', 'hloel', 'hlole', 'hlelo', 'hleol', 'hlleo', 'hlloe', 'hloel', 'hlole', 'hoell', 'hoell', 'holel', 'holle', 'holel', 'holle', 'ehllo', 'ehlol', 'ehllo', 'ehloleholl', 'eholl', 'elhlo', 'elhol', 'ellho', 'elloh', 'elohl', 'elolh', 'elhlo', 'elhol', 'ellho', 'elloh', 'elohl', 'elolh', 'eohll', 'eohll', 'eolhl', 'eollh', 'eolhl', 'eollh', 'lhelo', 'lheol', 'lhleo', 'lhloe', 'lhoel', 'lhole', 'lehlo', 'lehol', 'lelho', 'leloh', 'leohl', 'leolh', 'llheo', 'llhoe', 'lleho', 'lleoh', 'llohe', 'lloeh', 'lohel', 'lohle', 'loehl', 'loelh', 'lolhe', 'loleh', 'lhelo', 'lheol', 'lhleo', 'lhloe', 'lhoel', 'lhole', 'lehlo', 'lehol', 'lelho', 'leloh', 'leohl', 'leolh', 'llheo', 'llhoe', 'lleho', 'lleoh', 'llohe', 'lloeh', 'lohel', 'lohle', 'loehl', 'loelh', 'lolhe', 'loleh', 'ohell', 'ohell', 'ohlel', 'ohlle', 'ohlel', 'ohlle', 'oehll', 'oehll', 'oelhl', 'oellh', 'oelhl', 'oellh', 'olhel', 'olhle', 'olehl', 'olelh', 'ollhe', 'olleh', 'olhel', 'olhle', 'olehl', 'olelh', 'ollhe', 'olleh']
About The Author
I have more than 6 years of experience in the IT industry, and I have built a solid foundation in the creation and upkeep of online applications. I have constantly shown strong work ethics, self-motivation, and an aptitude for learning quickly throughout my career.