It works but i'm not satisfyed


#1

it works but i'm not satisfyed !

def remove_duplicates(lst):
lst1 =list(lst)
count = 0
for i in lst1:
if i == i:
return i

print remove_duplicates([1,2,4,2,5,7,2])

so i though about the fact that if looping and found that i = to itself, then it's the one i should remove: i wrote this part
if i == i:
return i
i didn't know how to do next, i hit "run" just for feedback , and it worked
I NEED AN EXPLINATION THANK YOU


Remove_duplicates
#2

There is a logic problem with the above. I cannot see how it will remove duplicates.

Let's first look at the indentation (the above will raise an error).

def remove_duplicates(lst):
    lst1 = list(lst)
    count = 0
    for i in lst1:
        if i == i:
            return i

Based on that code, the return value will be a single item (number or string, depending what is passed in). For starters, we will not need a count variable. More importantly, we need a new list that starts out empty, then we can append values if they do not exist in the new list.


    uniques = []
    for i in lst:
        if i not in uniques:
            uniques.append(i)
    return uniques

#3

the count var i just forgot it there , sorry about that
how ever i did already what you explained and tried different lists and it worked perfectly on the output( i changed numbers and duplicated them on purpose, but it gave me only one number for at a time, was perfect), yet when i submit didn't give me green down there to go next level,
Only when i submitted the code i provided to you early, i was offered green to go , next level.
i know it's odd what i'm saying but that what happened ,


#4

Given a list that contains duplicates, what does your return list look like? I just don't see how comparing something to itself qualifies as a valid comparison, and why would we return only a single value? i is not a list, only a value.


#5

This is the pice of code that gave me green to go next .
RESULT : 1 none
def remove_duplicates(lst):
lst1 =list(lst)
lst2 = []
count = 0
for i in lst1:
if i == i:
return iz

print remove_duplicates([1,2,4,2,5,7,2])

I tryed this code :
def remove_duplicates(lst):
lst1 =list(lst)
lst2 = []
count = 0
for i in lst1:
if i not in lst2:
lst2.append(i)
return lst2

print remove_duplicates([1,2,4,2,5,7,2])

RESULT :
[1, 2, 4, 5, 7]
result is right but the system didn't give me a green to go next .
now it just did, i asume you fixed it i guess =)


#6

The second example is correct code (mostly) so should pass. Why the first example passed is possibly due to the SCT not seeing the errors in the logic. The SCT is not exhaustive and only tests a small set of conditions.


#7

yeah,wat made me mad is that the second code i submit didn't pass , and i like to keep going with the caurse , i like it here ,
and please add C#, i need it for an aumented reality project i want work on with friends !
Thanx any way


#8

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.