Python | Remove all duplicates and permutations in nested list
Given nested list, the task is to remove all duplicated and permutations in that nested list.
Input: [[-11, 0, 11], [-11, 11, 0], [-11, 0, 11],
[-11, 2, -11], [-11, 2, -11], [-11, -11, 2]]
Output: {(-11, 0, 11), (-11, -11, 2)}
Input: [[-1, 5, 3], [3, 5, 0], [-1, 5, 3],
[1, 3, 5], [-1, 3, 5], [5, -1, 3]]
Output: {(1, 3, 5), (0, 3, 5), (-1, 3, 5)}
Code #1 : Using Map
# Python code to remove all duplicates# and permutations in nested list #InitialisationlistOfPermut = [[-11, 0, 11], [-11, 11, 0], [-11, 0, 11], [-11, 2, -11], [-11, -11, 2], [2, -11, -11]] # Sorting tuple then removingoutput = set(map(lambda x: tuple(sorted(x)),listOfPermut)) # printing outputprint(output) |
Output:
{(-11, 0, 11), (-11, -11, 2)}
Code #2 :
# Python code to remove all duplicates# and permutations in nested list #Initialisationinput = [[-11, 0, 11], [-11, 11, 0], [-11, 2, -11], [-11, -11, 2], [2, -11, -11]] # Sorting tuple then removingoutput = set(tuple(sorted(x)) for x in input) # printing outputprint(output) |
Output:
{(-11, 0, 11), (-11, -11, 2)}




