不使用任何库即可实现置换的最简单方法?

问题描述 投票:0回答:1

对于初学者,如何以最简单的方式显示字符串中的所有排列或任何其他可迭代的排列...

def permutations(iterable):
       #code here

例如Permutations("abc")

输出:"abc","acb","bac","bca","cba","cab"

python function permutation
1个回答
0
投票

这里:

def permutations(iterable): print(f'"{", ".join(li)}"')

permutations(abc)

输出:

"abc","acb","bac","bca","cba","cab"
© www.soinside.com 2019 - 2024. All rights reserved.