Program 15
15.Write a program that removes any repeated items from a list so that each item appears at most once. For instance, the list [1,1,2,3,4,3,0,0] would become [1,2,3,4,0].
n=int(input("Enter the number elements in the list:"))
l=[]
for i in range(1,n+1):
l.append(int(input("Enter the list %d Element:"%(i))))
print("The List elements are",l)
r=[]
for i in l:
if i not in r:
r.append(i)
print("remove repeated items from a list is:",r )
OOUTPUT:
>>>
======== RESTART: D:/old/r19 lab-python/15.py =======
Enter the number elements in the list:5
Enter the list 1 Element:45
Enter the list 2 Element:1
Enter the list 3 Element:2
Enter the list 4 Element:5
Enter the list 5 Element:45
The List elements are [45, 1, 2, 5, 45]
remove repeated items from a list is: [45, 1, 2, 5]
>>>
No comments:
Post a Comment