Python program to delete all duplicates from the list.

 Code:-

n=int(input(“Enter number of elements”))
mylist=[]
for i in range(n):
ele=int(input())
mylist.append(ele)
print(“list before deletion of repeated elementn”,mylist)
new_list=[]
for i in mylist:
if i not in new_list:
new_list.append(i)
print(“List after deletion of duplicatesn”,new_list)


Output:-

Enter number of elements10
1
2
3
4
5
4
3
2
1
3
list before deletion of repeated element
[1, 2, 3, 4, 5, 4, 3, 2, 1, 3]
List after deletion of duplicates
[1, 2, 3, 4, 5]



One thought on “Python program to delete all duplicates from the list.

Leave a Reply

Your email address will not be published.