Given a sorted array nums, remove the duplicates in-place
This is a job for itertools.groupby:

i = 0
for key, _ in groupby(nums):
    nums[i] = key
    i += 1
return i


A look at the implementation of groupby shows that it allocates \$O(1)\$ extra space, as required by the problem.

The i += 1 could be avoided using enumerate, like this:

i = -1 # in case nums is empty
for i, (key, _) in enumerate(groupby(nums)):
    nums[i] = key
return i + 1


but the need for an exceptional case to handle empty input is rather inelegant.