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 | Remove consecutive duplicates from list
- Python | Remove duplicates from nested list
- Python - Ways to remove duplicates from list
- Python | Remove all duplicates and permutations in nested list
- Python | Sort given list by frequency and remove duplicates
- Python | Remove duplicates based on Kth element tuple list
- Python | Remove duplicates in Matrix
- Remove all duplicates from a given string in Python
- Python | Remove all duplicates words from a given sentence
- Python - Remove Kth Index Duplicates in Tuple
- Python - Remove Equilength and Equisum Tuple Duplicates
- Python groupby method to remove all consecutive duplicates
- Python | Merging duplicates to list of list
- Python - List product excluding duplicates
- Python - Difference of List keeping duplicates
- Python | Consecutive duplicates all elements deletion in list
- Python | Program to print duplicates from a list of integers
- Python | Combine two lists by maintaining duplicates in first list
- Python | Program to count duplicates in a list of tuples
- Python | Remove all values from a list present in other list
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