Remove duplicate elements from lists
A neat and compact way to remove duplicate elements from lists.
competitive pythonQuestion #
With a given list of integers, write a python program to print this list after filtering out the duplicate values.
Input Format: #
In one line take the elements of the list L with each element separated by a space.
Output Format: #
Print the elements of the modified list in one line with each element separated by a space.
Solution #
Cool way (Neat as well): #
print(*list(map(int, set(list(input().split())))))
Explanation: #
Sets in Python can only store unique elements. Therefore converting the list into a sets and then converting it back into a list does the job.
Comments
Nothing yet.