Q.No.2 - Write a Programme to check if there is a duplicate element Present in the list or not. If that is present in the list then remove it from the List.

Sol.- Method no.1

list1=[2,3,1,4,2,4]
sets=set(list1)
if(len(sets)==len(list1)):
    print("List does not contain duplicate value")
else:
    print("List contain duplicate value")
    print("After remove duplicate value. List is",list(sets))

Explain : Step 1: We create a list1. Step 2: We convert list in set (set does not contain duplicate value). When we convert into duplicate value will be remove automatically. Step 3: Check length of Set and List if both equal then no duplicate value. Step 4: If it contain duplicate value, then else condition use and we convert set into list and not duplicate value show.

OUTPUT:

Sol.- Method no.2

list1=[2,4,6,82,4,2,7]
list2=[]
for i in list1:
    if i not in list2:
        list2.append(i)
print("Your list after remove duplicate", list2)


Explain : Step 1: We create a list1. Step 2: We create a empty list. Step 3: Use for i in list1. It check in list1 and then set if condition that means if i (0 to end of element) is not in list2 then add it in list2. Step 4: After that list2 is print. Duplicate items is not present in this list.

OUTPUT: