Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

write a program that remove duplicte from list?

0 votes
asked Dec 4, 2019 by thota

5 Answers

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

x.remove(2)

x

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

s = set(l)
l = s
print(l)
+2 votes
answered Dec 15, 2019 by gameforcer (2,990 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)

commented Jun 13, 2021 by ITSME (760 points)
what an professional answer dude
–1 vote
answered Feb 12, 2020 by shrihari689 (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)
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...