def remove_duplicates(lst):
for i in lst:
n = int(i in lst)
return n
I did this as part of an overall code, but the rest was unnecessary (not shown), since this returns the desired result. Can someone explain why?
def remove_duplicates(lst):
for i in lst:
n = int(i in lst)
return n
I did this as part of an overall code, but the rest was unnecessary (not shown), since this returns the desired result. Can someone explain why?
What you are doing here, is to check if the list element is in the list, which is obviously True. And then turn True into an integer, which is 1.
At the very end you return the 1 (the integer you created by turning True into an integer).
def remove_duplicates(n):
newlist=
for i in n:
if i not in newlist:
newlist.append(i)
return newlist
It works for me.
def remove_duplicates(n):
newlist=[]
for i in n:
if i not in newlist:
newlist.append(i)
return newlist
Hey guys, what about this? trying to figure out why it returns 4 instead of 4 and 5
def remove_duplicates(l):
l_mod =
for i in l:
l_mod.append(i)
return l_mod
for a in l_mod:
if l_mod.count(a) > 1:
l_mod.remove(a)
return l_mod
Try this:
def remove_duplicates(l):
l_mod =
for i in l:
l_mod.append(i)
for a in l_mod:
if l_mod.count(a) > 1:
l_mod.remove(a)
return l_mod
what i figured is in your first return
since you are still going to make use of the l_mod variable, i dont think there is any need returning it back to the function yet