Remove duplicate value in list - Trick

Example 1:

let's consider list 

l1 = [1,2,3,4,5,2,3,4,8]

print(l1) # display with duplicate value 

print(list(set(l1))) # display list without dublicate

[1, 2, 3, 4, 5, 8]

Example 2:

new_l1 = list(dict.fromkeys(l1)) # fromkeys dict property of python

print(new_l1) #display list without duplicate 

Example 3:

by loop

ar = []

for i in l1:

    if i not in ar:

        ar.append(i)

print(ar)



Comments