def remove_duplicates(numbers):
    for p1 in numbers:
    for p2 in d:
    return l

Why does it work ? Can someone explain the whole procedure please ?


It works because dictionaries are sets of key/value pairs. A set cannot have any repeated values. consequently, with each assignment to the dictionary, any key which is already there is overwritten. The final dictionary has only unique keys. The second loop copies the keys to a list.

However, using a solution that we do not understand is a pretty good indication that it was borrowed from somewhere else and is not your original work. For the practice, see if you cannot come up with a solution of your own using a different approach. There are several ways to go about it.


What I did was create a new variable and set it as set of the list. Then I returned the variable. That took 2 lines and worked for me


Yes, but like the above it does not retain the order of the original sequence which a good solution will be able to do.


A post was split to a new topic: It works but i'm not satisfyed


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.