# 14. remove duplicares. Could someone help me with my code

#1

``````def remove_duplicates(x):
c = []
c += x
for n in c:
for m in c:
if m == n:
c.append(n)
return c
print remove_duplicates([4, 5, 5, 4])``````

``Replace this line with your code.``

#2

what are you doing on this line:

``c += x``

`x` and `c` are both lists, not sure what you are trying to achieve here, anyway, if you add print statement:

``````c += x
print c, "see empty"``````

you will see `c` is empty, you might want to rethink that.

#3

I know it may seem hard but I did it in 3 lines! Yes, 3 lines!
Code:

def remove_duplicates(numbers):
new_list = set(numbers)
return new_list

Apparently set does it all for you so sit back and relax

#4

How does this code work?

#5

you can check here to see how the built in set function works

#7

``````def remove_duplicates(numbers):
return set(numbers)``````

Boom. 1 line.

#8

what does the set() function do?

#9

Here is a simple way to deal this drill but hint that affords:
def remove_duplicates(nums):
return set(nums)
It's working

#10

If you don't want to use set because you want to understand this function in detail, I recommend you to try to understand my code:

def count(sequence, item):
result=0
for i in sequence:
if i==item:
result += 1
return result

def remove_duplicates(lst):
lst2=[]
for i in lst:
lst2.append(i)
for i in lst2:
while count(lst2, i)>1:
lst2.remove(i)
return lst2

#11

Set function removes repeated words.

#12

Doesn't set just change the data type to a set? Like a dictionary without any values?

#13

``````def remove_duplicates(items):
new_list = []  #
for x in items:
if x not in new_list:
new_list.append(x)
return new_list
print remove_duplicates([1,2,3,4,5,2,3,5])``````

Creat an empty list, check ur empty list if it alrady holds the same element, if not append that element!