用于在Python中置换给定字符串内置函数的Python程序
给出字符串。我们的任务是显示给定字符串的排列。在此使用内置函数置换(可迭代)在python中解决此问题。
例子
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
热门推荐
1 训练狗狗搜寻
2 如何训练狗狗装死
3 狗狗训练书
6 怎么训练狗狗拜年
8 狗狗训练游戏
10 狗狗嗅觉训练
11 怎么训练狗狗在笼子里不叫
12 怎么训练狗狗站立走路
13 怎么训练狗狗在马桶上
14 狗狗尿尿怎么训练
15 训练狗狗用品
16 泰迪狗狗的训练方法大小便
17 训练狗狗可以打吗
18 王曼丽的狗狗训练