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 #Initialisation listOfPermut = [[-11, 0, 11], [-11, 11, 0], [-11, 0, 11], [-11, 2, -11], [-11, -11, 2], [2, -11, -11]] # Sorting tuple then removing output = set(map(lambda x: tuple(sorted(x)),listOfPermut)) # printing output print(output) |
chevron_right
filter_none
Output:
{(-11, 0, 11), (-11, -11, 2)}
Code #2 :
# Python code to remove all duplicates # and permutations in nested list #Initialisation input = [[-11, 0, 11], [-11, 11, 0], [-11, 2, -11], [-11, -11, 2], [2, -11, -11]] # Sorting tuple then removing output = set(tuple(sorted(x)) for x in input) # printing output print(output) |
chevron_right
filter_none
Output:
{(-11, 0, 11), (-11, -11, 2)}
Recommended Posts:
- Python | Remove duplicates from nested list
- Python | Check if a nested list is a subset of another nested list
- Python | Remove all occurrences in nested list
- Python | Sort given list by frequency and remove duplicates
- Python Remove Duplicates from a List
- Python - Ways to remove duplicates from list
- Python | Remove consecutive duplicates from list
- Python | Remove duplicates based on Kth element tuple list
- Remove all duplicates from a given string in Python
- Python groupby method to remove all consecutive duplicates
- Python | Remove all duplicates words from a given sentence
- Python | Pair and combine nested list to tuple list
- Python | Convert a nested list into a flat list
- Python | Find maximum length sub-list in a nested list
- Python | Convert given list into nested list
- Python | Convert string List to Nested Character List
- Python - Remove Equilength and Equisum Tuple Duplicates
- Python | Remove duplicate dictionaries from nested dictionary
- Python - Remove nested records from tuple
- Python - Remove None Nested Records
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

