- Trending Categories
- Data Structure
- Operating System
- C Programming
- 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 −
# 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)
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.
In this article, we have learned about how we can make a Python Program to print all permutations of a given string.
- Print all permutations of a given string
- C Program to print all permutations of a given string
- Print all permutations of a string in Java
- Print all distinct permutations of a given string with duplicates in C++
- 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 palindrome permutations of a string in C++
- Java Program to print distinct permutations of a string
- 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++
- All permutations of a string using iteration?
- C++ Program to Find the Number of Permutations of a Given String
- Print k different sorted permutations of a given array in C Program.