Skip to content

Instantly share code, notes, and snippets.

@accakks
Created June 12, 2020 19:39
Show Gist options
  • Save accakks/fbf2383ce782bbf089c68a807695b3e1 to your computer and use it in GitHub Desktop.
Save accakks/fbf2383ce782bbf089c68a807695b3e1 to your computer and use it in GitHub Desktop.
Print all permutations of a given string in Python
'''
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