तार दिया गया है। हमारा काम दिए गए स्ट्रिंग के क्रमपरिवर्तन को प्रदर्शित करना है। इनबिल्ट फ़ंक्शन क्रमपरिवर्तन (पुनरावृत्तीय) का उपयोग करके अजगर में इस समस्या को हल करें।
उदाहरण
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