时间:2021-07-01 10:21:17 帮助过:58人阅读
for item in list(perms([1, 2, 3,4])):
print item
第二种方法:python标准库
源代码如下:
def perms(elements):
if len(elements) <=1:
yield elements
else:
for perm in perms(elements[1:]):
for i in range(len(elements)):
yield perm[:i] + elements[0:1] + perm[i:]
for item in list(perms([1, 2, 3,4])):
print item