第一种方法:递归
复制代码 代码如下:
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
Copyright© 2013-2020
All Rights Reserved 京ICP备2023019179号-8