Python itertools Module
"itertools" are an inbuilt module in Python which is a collection of tools for handling iterators. It is the most useful module of Python. Here, a string is provided by the user and we have to print all the possible permutations of the given string in Python. As we all know the permutation is a way of arranging the elements of a group or set in a specific order or sequence which makes a different group. We all have calculated the permutations by using the pen and paper but here we will do this by using the Python programming language in a very small time.
Algorithm to solve the problem:
- Initially, we will import the permutation function from the itertools module.
- Take the string from the user and assign it in a variable s.
- Generate all permutation using the permutation function and assign it in a variable p.
- Since all elements of p are in tuple form. So, convert it in the list.
- At last, add all list elements and print it which is our possible permutations.
Python program to find all permutations of a given string
Output
need an explanation for this answer? contact us directly to get an explanation for this answer