remove_dublicates


#1

def remove_duplicates(lists):

new_list = []
for item in lists:
    if item not in new_list:
        new_list.append(item)
return new_list

any one explain this code clearly?


#2

I think you know what each of those things do, if for no other reason that it almost reads like English along with that you know what the end result is. Execute it in your head for a small list and see what happens.

Explain it clearly? The code already does. Is there something in particular that eludes you?


#3

the script reads the list one by one and store it into the new list.
If the new list does not have the number, it will append onto it
for example: [1,2,1], the first round stores 1 and the second round stores 2. In the third round, it detects 1 in the new list, then it wont append to the new list.

somehow, there is a simpler way
def remove_duplicates(x):
newList=list(set(x))
return newList


#4

A set is very much like a dictionary. A dictionary will not have duplicate keys, and a set will not have duplicate values.