Duplicate within k positions

Write nearby_duplicate(nums, k) that returns True if some value appears twice at positions at most k apart.

nearby_duplicate([1, 2, 3, 1], 3)        ->  True
nearby_duplicate([1, 2, 3, 1, 2, 3], 2)  ->  False
nearby_duplicate([1, 0, 1, 1], 1)        ->  True

The point is to practise a dictionary from value to its last position.

def nearby_duplicate(nums, k):
    ...