

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Permutation of a given string using the inbuilt function in Python
In this tutorial, we are going to find the permutation of a string using the inbuilt function of Python called permutations. The method permutations is present in the itertools module.
Procedure To Find The Permutation Of A String
- Import the itertools module.
- Initialize the string.
- Use the itertools.permutations method to find the permutation of the string.
- In the third step, the method returns an object and convert it into a list.
- List contains a permutation of string as tuples.
Example
Let's see the program.
## importing the module import itertools ## initializing a string string = "XYZ" ## itertools.permutations method permutaion_list = list(itertools.permutations(string)) ## printing the obj in list print("-----------Permutations Of String In Tuples----------------") print(permutaion_list) ## converting the tuples to string using 'join' method print("-------------Permutations In String Format-----------------") for tup in permutaion_list: print("".join(tup))
Output
If you run the above program, you will get the following result.
-----------Permutations Of String In Tuples---------------- [('X', 'Y', 'Z'), ('X', 'Z', 'Y'), ('Y', 'X', 'Z'), ('Y', 'Z', 'X'), ('Z', 'X', 'Y'), ('Z', 'Y', 'X')] -------------Permutations In String Format----------------- XYZ XZY YXZ YZX ZXY ZYX
If you have any doubts regarding the program, please do mention them in the comment section.
- Related Questions & Answers
- Python program for the permutation of a given string inbuilt function in python
- Python program for permutation of a given string inbuilt function in python
- Print all permutation of a string using ArrayList in Java
- How to find all the permutation of the string by backtracking using C#?
- Inbuilt Data Structures in Python
- Rearrange positive and negative numbers using inbuilt sort function in C++
- Find smallest permutation of given number in C++
- Python program to count the number of vowels using set in a given string
- Python program to count the number of vowels using sets in a given string
- Permutation in String in C++
- Python program to change character of a string using given index
- Generate all permutation of a set in Python?
- Python Program to Calculate the Length of a String Without Using a Library Function
- C++ Permutations of a Given String Using STL
- Python program to count number of vowels using set in a given string
Advertisements