Created
June 12, 2020 19:39
-
-
Save accakks/fbf2383ce782bbf089c68a807695b3e1 to your computer and use it in GitHub Desktop.
Print all permutations of a given string in Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
Write a program to print all the permutations of a given string. For example: | |
Input : ABC | |
Output: ABC ACB BAC BCA CAB CBA | |
''' | |
from itertools import permutations | |
def print_permutations(s): | |
"""Prints permutations of a given string""" | |
ans = list(permutations(s)) | |
print(s) | |
for permutation in ans: | |
print(str().join(permutation), end = " ") | |
s = input('Enter input string\n') | |
print_permutations(s) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment