satya

Wednesday, October 7, 2020

Program 15

                                                                             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]

>>> 

==== RESTART: D:/old/r19 lab-python/15.py ===========
Enter the number elements in the list:7

Enter the list 1 Element:1

Enter the list 2 Element:1

Enter the list 3 Element:2

Enter the list 4 Element:5

Enter the list 5 Element:6

Enter the list 7 Element:3

The List elements are [1, 1, 2, 5, 6, 2, 3]

remove  repeated items from a list is: [1, 2, 5, 6, 3]

No comments:

Post a Comment

Program 30

                                                                         Program 30 Write a Python class to implement pow(x, n). class Pow1:...