All possible unique permutations
Problem to find the unique permutation in given list.
Example-1:
Input : n = [ 1, 2, 1] Output : [[1, 1, 2], [1, 2, 1], [2, 1, 1]]
Example-2:
Input : n = [ 1, 2, 3] Output : [[1, 2, 3], [1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 1, 2], [3, 2, 1]]
Solution
from itertools import permutations n = [ 1, 2, 1] a = list(permutations(n,3)) b = set(a) c = [list(x) for x in list(b)] d = sorted(c) print(d)
Output
[[1, 1, 2], [1, 2, 1], [2, 1, 1]]