Removing Duplicates

The questions below are due on Sunday June 30, 2024; 10:00:00 PM.
 
You are not logged in.

Please Log In for full access to the web site.
Note that this link will take you to an external site (https://shimmer.mit.edu) to authenticate, and then you will be redirected back to this page.

Write a function remove_ duplicates that removes elements from a list. For the purpose of this problem, a duplicated element is any element which appears exactly twice. You may assume all elements in the list are hashable.

For example:

list1 = ["hi", 1, 2, 3, 3, "hi", "hi", 1, 6]
result = remove_duplicates(list1)
print(result)
print(list1)

Should print the resulting lists:

["hi", 2, "hi", "hi", 6]
["hi", 1, 2, 3, 3, "hi", "hi", 1, 6]

Note that the original list is unchanged, meaning that your function should create and return a new list. Also, the order of elements in the output list should be preserved, besides the removal of the duplicates. When you are ready (once you have simulated by hand and tested on your own machine and are convinced that your program will do the right thing), upload your file below for testing:

Relevant Readings

  No file selected

Next Exercise: Warehouse

Back to exercises