문자열이 주어집니다. 우리의 임무는 주어진 문자열의 순열을 표시하는 것입니다. 내장 함수 순열(반복 가능)을 사용하여 파이썬에서 이 문제를 해결하세요.
예시
Input: string = 'XYZ'
Output: XYZ
XZY
YXZ
YZX
ZXY
ZYX
알고리즘
Step 1: given string. Step 2: Get all permutations of a string. Step 3: print all permutations.
예시 코드
from itertools import permutations
def allPermutations(str1):
# Get all permutations of string 'ABC'
per = permutations(str1)
# print all permutations
print("Permutation Of this String ::>")
for i in list(per):
print (''.join(i))
# Driver program
if __name__ == "__main__":
str1 = input("Enter the string ::>")
allPermutations(str1)
출력
Enter the string ::> abc Permutation Of this String ::> abc acb bac bca cab cba