2024-04-25 09:59:05 发布
网友
我想在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)的所有这些排列的一种方便方法是什么?你知道吗
正如Ashwini Chaudhary在评论中指出的:
from itertools import permutations permutes = permutations([1,2,3,4,5]) for li in permutes: # do stuff
正如Ashwini Chaudhary在评论中指出的:
相关问题 更多 >
编程相关推荐