All problems
Remove Duplicates from Sorted List
Problem
Remove duplicates from a sorted list so that each value appears exactly once.
Because the list is sorted, duplicates are adjacent. Scan once and keep a value only when it differs from the last kept value.
Return the resulting list.
Hint
Compare each value with the last one you kept, not with the previous element alone.
Test cases
case 1
in: [[1,1,2]]
expected: [1,2]
case 2
in: [[1,1,2,3,3]]
expected: [1,2,3]
case 3
in: [[]]
expected: []
case 4
in: [[-3,-1,-1,0,0,2]]
expected: [-3,-1,0,2]
Starter codePython
def remove_duplicates(values):
# Your code here
pass4 test cases · run your code against them in the editor