Remove duplicates


#1

I want to make a code that first import all items together in a new list b then count each item if item count
is more than 1 remove one copy and so on till count = 1 then return new list b
I knew it is a stupid harder way than the tip but I want to complete it to feel the achievement

def remove_duplicates(a):
        b=[]
        for i in a:
            b.append(i)
            for i in b:
                count = 0
                if i is i: #I belive that the error is somewhere here
                    count += 1
                    while count < 1:
                        b.remove(i)
                        count -= 1
        return b

Oops, try again. remove_duplicates([4, 5, 5, 4]) returned [4, 5, 5, 4] instead of [4, 5]


#2

return b is one the same vertical line as for in the 3rd line "bad copying :smiley: "


#3
  1. if i is i: i will always be i?

  2. return b should be on line two.

  3. Your indentation is wrong, as the while loop will never execute.

  4. If you want it to end when count = 1 it will end after 1 element.

  5. This is terribly inefficient, and in programming efficiency is key. You should focus on being efficient, not doing things in the hardest way possible.


#4

This is terribly inefficient, and in programming efficiency is key. You should focus on being efficient, not doing things in the hardest way possible

that's the way I started and I want (hoped to) finish it to feel I am more efficient with python not making it harder to my self..
first of all thanks for replying
but man your words are hard a bit .. this hurt me :pensive:


#5

and by the way I solved it

def remove_duplicates (a):
	i = []
	for e in a:
		if e not in i:
			i.appened(e)
	return i

#6

This shouldn't work because:

i.appened(e)

'appened' isn't a thing.


#7

I corrected it but pasted the old copy by mistake