- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Python Program to print all permutations of a given string
In this article, we will learn about the solution to the problem statement given below.
Problem statement − We are given a string we need to display all the possible permutations of the string.
Now let’s observe the solution in the implementation below −
Example
# conversion def toString(List): return ''.join(List) # permutations def permute(a, l, r): if l == r: print (toString(a)) else: for i in range(l, r + 1): a[l], a[i] = a[i], a[l] permute(a, l + 1, r) a[l], a[i] = a[i], a[l] # backtracking # main string = "TUT" n = len(string) a = list(string) print("The possible permutations are:",end="\n") permute(a, 0, n-1)
Output
The possible permutations are: TUT TTU UTT UTT TUT TTU
All the variables are declared in the local scope and their references are seen in the figure above.
Conclusion
In this article, we have learned about how we can make a Python Program to print all permutations of a given string.
- Related Articles
- C Program to print all permutations of a given string
- Print all permutations of a given string
- Python Program to Print All Permutations of a String in Lexicographic Order without Recursion
- Python Program to Print All Permutations of a String in Lexicographic Order using Recursion
- Print all distinct permutations of a given string with duplicates in C++
- Print all permutations of a string in Java
- Java Program to print distinct permutations of a string
- Print all palindrome permutations of a string in C++
- How to find all possible permutations of a given string in Python?
- Python program to get all permutations of size r of a string
- Print all the palindromic permutations of given string in alphabetic order in C++
- Program to print all substrings of a given string in C++
- C++ Program to Find the Number of Permutations of a Given String
- Print k different sorted permutations of a given array in C Program.
- Python program to print all distinct elements of a given integer array.

Advertisements