我想在Python中检查(1,2,3,4,5)的所有排列并为每个排列计算一些内容,例如
for li in PermutationLists: # PermutationLists = [[1,2,3,4,5],[1,2,3,5,4],...]
print li[0]-li[1]+li[2]-li[3]+li[4]
迭代(1,2,3,4,5)的所有这些排列的方便方法是什么?
答案 0 :(得分:2)
Ashwini Chaudhary在评论中指出:
from itertools import permutations
permutes = permutations([1,2,3,4,5])
for li in permutes:
# do stuff