Removing Duplicates from list



Method 1:
a = [2,2,1,5,4,2,3,3]
b = set(a)
c = [] 
for i in a:  
    if i not in b:
        c.append(i) 
        b.add(i)
print(c) 
output:[2, 1, 5, 4, 3]

Method 2:
a = [2,2,1,5,4,2,3,3]
b = set(a)
print(b)
Output:[1,2,3,4,5]














Post a Comment

0 Comments