The job is simple. We need to take a list, with duplicate elements in it and generate another list which only contains the element without the duplicates in them.
Input : [2, 4, 10, 20, 5, 2, 20, 4] Output : [2, 4, 10, 20, 5] Input : [28, 42, 28, 16, 90, 42, 42, 28] Output : [28, 42, 16, 90]
We can use not in on list to find out the duplicate items. We create a result list and insert only those that are not already not in.
[2, 4, 10, 20, 5]
A quick way to do the above using set data structure from the python standard library (Python 3.x implementation is given below)
[2, 4, 10, 20, 5]
- Python - Ways to remove duplicates from list
- Python | Remove consecutive duplicates from list
- Python | Remove all duplicates and permutations in nested list
- Python | Remove duplicates from nested list
- Python | Sort given list by frequency and remove duplicates
- Python | Remove duplicates based on Kth element tuple list
- Python | Merging duplicates to list of 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 | Remove duplicates in Matrix
- Python - Remove Equilength and Equisum Tuple Duplicates
- Python - Remove Kth Index Duplicates in Tuple
- Python - Remove alternate consecutive duplicates
- Python - Remove K length Duplicates from String
- Python | Program to print duplicates from a list of integers
- Python | Program to count duplicates in a list of tuples
- Python | Combine two lists by maintaining duplicates in first list
- Python | Consecutive duplicates all elements deletion in list
- Python - Ways to print longest consecutive list without considering duplicates element
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.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.
Improved By : codeslord