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


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

Replace this line with your code.


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.


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

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

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


How does this code work?


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


How about just;

def remove_duplicates(numbers):
    return set(numbers)

Boom. 1 line.


what does the set() function do?


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


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):
for i in sequence:
if i==item:
result += 1
return result

def remove_duplicates(lst):
for i in lst:
for i in lst2:
while count(lst2, i)>1:
return lst2


Set function removes repeated words.


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


def remove_duplicates(items):
    new_list = []  #
    for x in items:
        if x not in new_list:
    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!