Friday, 10 December 2021

Python-Slip1A-Write a Python program to accept n numbers in list and remove duplicates from a list.

 Write a Python program to accept n numbers in list and remove duplicates from a list.  

 First- Solution

a=[]

n= int(input("Enter the number of elements in list:-"))

for x in range(0,n):

element=int(input("Enter element" + str(x+1) + ":"))

a.append(element)

b = set()

unique = []

for x in a:

if x not in b:

unique.append(x)

b.add(x)

print("Non-duplicate items:-")

print(unique)


  Second- Solution

 def rduplicate(A):

 newlist = []

 for n in A:

 if n not in newlist:

 newlist.append(n)

return newlist

A=list()

n=int(input("Enter the size of the List -"))

print("Enter the number -")

for i in range(int(n)):

 k=int(input(""))

 A.append(int(k))

print("The new list is:-",rduplicate(A))