def extend_nums(nums, min_needed):
    while len(nums) < min_needed:
        new_nums = []
for index in range(1, len(nums)):
    new_nums.append(nums[index - 1])
new_nums.append(mean(nums[index - 1], nums[index]))
new_nums.append(nums[-1])
nums = new_nums
return nums
How can a list be extended uniformly to include extrapolated mean values?