I am the Co-Founder of The Data Monk. I have a total of 6+ years of analytics experience
3+ years at Mu Sigma
2 years at OYO
1 year and counting at The Data Monk
I am an active trader and a logically sarcastic idiot :)
Follow Me
>> l1=[1,2,3,2,4,1,5,3,6]
#l1 is the given list, we need to remove duplicates from the list l1
#create a new empty list
l2=[]
#loop for all elements in l1
for l in l1:
if(l not in l2):
l2.append(l)
print(l2)
Answers ( 7 )
res = []
for i in test_list:
if i not in res:
res.append(i)
res = []
for i in test_list:
if i not in res:
res.append(i)
l=[1,2,3,3,4,4,5]
for i in l:
while l.count(i)>1:
l.remove(i)
Create a dictionary, using the List items as keys. This will automatically remove any
duplicates because dictionaries cannot have duplicate keys.
mylist1 = [1,1,2,2,3,3,3,3,4]
mylist1 = list(dict.fromkeys(mylist1))
print(mylist1)
#output
1 2 3 4
li = list(map(int, input().split()))
emp = []
for i in range(len(li)):
if(li[i] in emp):
continue
else:
emp.append(li[i])
>> l1=[1,2,3,2,4,1,5,3,6]
#l1 is the given list, we need to remove duplicates from the list l1
#create a new empty list
l2=[]
#loop for all elements in l1
for l in l1:
if(l not in l2):
l2.append(l)
print(l2)
output-
[1,2,3,4,5,6]
t=[1,2,1,1,2,3,4,4]
p=[]
[p.append(x) for x in t is x not in p]
print(p)