Python program to remove Duplicates elements from a List?
Answers
hey mate here's ur ans ^_^
Python | Remove Duplicates from a List
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.
Examples:
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]
hope it helpzz uhh
Hey there!!
To remove the duplicates from a list, we first add them to a dictionary and then remove the similarities in the dictionaries.
Let's say we have a list which is [1,1,2,2,3,3,4,4,5,5]
Let's assign it a variable first, my_list = [1,1,2,2,3,3,4,4,5,5]
Now, we will have to add all of them to a dictionary and remove the duplicates.
my_list = list(dict.fromkeys(my_list))
print(my_list)
The output would be : [1,2,3,4,5]
Hope my answer helps!