我正在尝试使用itertools来使此代码表现更好,并且变得更加Pythonic
def get_permutations():
out = []
for a in range(0,6):
for b in range(0, 6):
for c in range(0, 6):
for d in range(0, 6):
for e in range(0, 6):
for f in range(0, 6):
out.append([a,b,c,d,e,f])
return out
我认为我应该使用itertools.permutations and Itertools.chain,但我不确定如何将它们放在一起以将等效的结果作为列表或迭代器。如果您有另一个不使用Itertools的解决方案,我也会考虑。
您不是在寻找itertools.combinations_with_replacement([0, 1, 2, 3, 4, 5], 6)
吗?:)