Remove duplicates in place
A sorted list has duplicates next to each other. Remove them without
making a new list, using two positions: a reader that visits every
item, and a writer that marks where the next kept item goes. Whenever
the reader sees a value different from the last kept one, copy it to the
writer's position and advance the writer. At the end, the first writer
items are the unique values.
Write dedupe(sorted_nums) that rearranges the list so its first part
holds the unique values in order, and returns how many there are. The
point is to practise the reader-and-writer method rather than build a new
list or use a set.
nums = [1, 1, 2, 3, 3, 3]
dedupe(nums) -> 3 and nums now starts [1, 2, 3, ...]
def dedupe(sorted_nums):
...