Reputation: 169
I want to go through all permutations of (1,2,3,4,5) in Python and calculate something for each permutation, like
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]
What would be a convenient way to iterate through all these permutations of (1,2,3,4,5)?
Upvotes: 1
Views: 239
Reputation: 54173
As Ashwini Chaudhary pointed out in the comments:
from itertools import permutations
permutes = permutations([1,2,3,4,5])
for li in permutes:
# do stuff
Upvotes: 2