write a program that remove duplicte from list?

+1 vote
answered Dec 8, 2019 by (200 points)
```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)
print("Non-duplicate items:")
print(unique)```
commented Feb 12 by (110 points)
b = set()
unique = []
for x in a:
if x not in b:
unique.append(x)
print("Non-duplicate items:")
print(unique)
print(''hello world'')
answered Dec 11, 2019 by anonymous
x=[1,2,2,3,4,5]

x.remove(2)

x

o/p:[1,2,3,4,5]
+1 vote
answered Dec 12, 2019 by Kshitinjay Kumar
l = [1,2,3,4,1,2,3]

s = set(l)
l = s
print(l)
+1 vote
answered Dec 15, 2019 by (2,950 points) 1 flag

The easiest way is to convert the list into a set and back into a list, since values in a set are unique by definition.

Example:

foo = [1,1,2,3,4,4,5]
print('before: ', foo)
foo = list(set(foo))
print('after: ', foo)

–1 vote
answered Feb 12 by (120 points)
# One Line of Code!

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

print("Before: ",num)
num=list(set(num))

print("After: ",num)