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]
- Python | Remove consecutive duplicates from list
- Python | Ways to remove duplicates from list
- Python | Remove duplicates from nested list
- Python | Sort given list by frequency and remove duplicates
- Python | Remove all duplicates and permutations in nested list
- Remove all duplicates from a given string in Python
- Python | Remove all duplicates words from a given sentence
- Python groupby method to remove all consecutive duplicates
- Python | Merging duplicates to list of list
- Python | Combine two lists by maintaining duplicates in first list
- Python | Program to count duplicates in a list of tuples
- Python | Program to print duplicates from a list of integers
- Python | Remove all values from a list present in other list
- Python list remove()
- Python | Remove None values from 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.