To repeat my earlier suggestion…
Your code contains most of the needed parts.
- a new list that is initialized to empty.
- a for loop to iterate the old list
- an if statement to check the old item against the new list (not quite)
- a return statement that sends the new list back to the caller.
new_list =  # notice no white space between brackets
for i in x:
if i not in new_list:
Note that we have not used
list.remove()? We instead use the logical
not to determine if the item is NOT in the new_list. If so, then it can be added. We do nothing to modify the original list.
You might do well to read up on the built in list method and see what it really does. It has no return value so
a above will be
>>> x = [4,5,5,4]
[5, 5, 4]
>>> a = x.remove(5)
>>> print (a)
It should be noted as well that
list.remove() is not selective but removes the first item that matches the argument. As such, the first 4, and first 5 are removed, leaving a list that is
[5, 4] which raises the SCT error message. The method illustrated above using
not in does not alter the order of the returned list since the first 4 and first 5 have already been examined and added to the new list. The second ones are ignored.