SEP = ','
def permutation(arr, n):
length = len(arr)
return arr if n == 1 else [ arr[i] +SEP+ e for i in range(length) for e in permutation([ arr[j] for j in range(length) if j != i ], n-1) ]
用python实现排列
最新推荐文章于 2023-04-16 00:08:45 发布
SEP = ','
def permutation(arr, n):
length = len(arr)
return arr if n == 1 else [ arr[i] +SEP+ e for i in range(length) for e in permutation([ arr[j] for j in range(length) if j != i ], n-1) ]