Problem with remove_duplicates


#1

def remove_duplicates(stuff):
    single = [ ]
    for i in stuff:
        x = stuff[i]
        if i not in stuff[x:]:
            single.append(i)
return single

#2

And I don't know how to indent my code here.


#3

Have you checked the community forum for tips and resources and how to format code samples?


#4

Ok, I solved it differently. But would still be interesting to know how it's working.


#5

You still didn't locate that article on how to format code samples, did you? If you want us to help you, then take the time to read and learn how to format code.

What is more, new topics have a template built in if one takes the time to read and follow the instructions written there. Code may be pasted in to the section indicated ("Replace this line with your code").


#6

Now, I did. Was just busy and tired. Would be glad if you'd help me.


#7

Much better. Thanks for looking that up.

single = []

Normally, an empty list is written without a space inside. May not matter, though.

x = stuff[i]

i is already an item from the list. It is not an index.

if i not in single:

Be sure your return line is in the function. Indent with four spaces.


#8

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