Python | Permutation of a given string using inbuilt function
A permutation, also called an “arrangement number” or “order”, is a rearrangement of the elements of an ordered list S into a one-to-one correspondence with S itself. A string of length n has n! permutation.
Examples:
Input : str = 'ABC'
Output : ABC
ACB
BAC
BCA
CAB
CBA
We have existing solution for this problem please refer Permutations of a given string using STL link. We can also solve this problem in python using inbuilt function permutations(iterable).
# Function to find permutations of a given string from itertools import permutations def allPermutations(str): # Get all permutations of string 'ABC' permList = permutations(str) # print all permutations for perm in list(permList): print (''.join(perm)) # Driver program if __name__ == "__main__": str = 'ABC' allPermutations(str) |
Output:
ABC ACB BAC BCA CAB CBA
Permutation and Combination in Python
Recommended Posts:
- Python | Ways to find all permutation of a string
- Inbuilt Data Structures in Python
- Python program to count upper and lower case characters without using inbuilt functions
- Generate all permutation of a set in Python
- Permutation and Combination in Python
- Python | Check if given string can be formed by concatenating string elements of list
- String slicing in Python to check if a string can become empty by recursive deletion
- Python | Check if string ends with any string in given list
- String slicing in Python to rotate a string
- Python | Check if a given string is binary string or not
- numpy string operations | less() function
- numpy string operations | istitle() function
- numpy string operations | isnumeric() function
- numpy string operations | isdecimal() function
- numpy string operations | isdigit() function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



