Removing dupilcates- Using double loop ? ><` Please help ><`


#1

<PLEASE USE THE FOLLOWING TEMPLATE TO HELP YOU CREATE A GREAT POST!>

<Below this line, add a link to the EXACT exercise that you are stuck at.>

<In what way does your code behave incorrectly? Include ALL error messages.>

<What do you expect to happen instead?>

```python

I tried removing the duplicates using a double loop ><`

def remove_duplicates(numbers):

noDuplicate=[]

for i in range(0,len(numbers)):
    for j in range(1,len(numbers)+1):
        
        if(numbers[j] == numbers(i)):
            noDuplicate.append(numbers(j))
        else:
            noDuplicate.append(numbers(i))
            noDupicate.append(numbers(j))
            
return noDuplicate

Can it work using a double loop ? ><` .

<do not remove the three backticks above>

#2

@sukuraisonia

Yes, it can.

Do I recommend it. No.

You already have the concept down but using the second loop is just wasting resources.

You should just simplify it to.

Python Code:

def remove_duplicates(aList):
    tmp = []
    for item in aList:
        if item not in tmp:
            tmp.append(item)
    return tmp

Or a single line,

Python Code:

def remove_duplicates(aList):
    return list(set(aList))

The above does not respect order mind you, but it is fast.

As always, as the programmer it is up to you on how you will handle something. If you need additional help feel free to ask.


#3

Thank you for explaining it to me :slight_smile: I really appreciate it :slight_smile: :slight_smile: . Your explanation really helped me :slight_smile: .I will try to make the double loop work when I do I`ll show you the code again :relaxed: I will try not to trouble you too much :). Thank you for taking time to help me :slight_smile: .Have a great day!!! :grin: