+ 3

How easy way to find the permutation in python ?

14th Apr 2018, 1:57 PM
Rajaprithya. P
Rajaprithya. P - avatar
2 Réponses
+ 1
the simplest approach i know is by using the itertool module. # A Python program to print all # permutations using library function from itertools import permutations # Get all permutations of [1, 2, 3] perm = permutations([1, 2, 3]) # Print the obtained permutations for i in list(perm): print (i) output: (1, 2, 3) (1, 3, 2) (2, 1, 3) (2, 3, 1) (3, 1, 2) (3, 2, 1)
18th Jul 2018, 3:39 PM
Harry
Harry - avatar