Squares of a sorted list

A sorted list may contain negatives, so squaring the values does not keep them sorted: [-3, 1, 2] squares to [9, 1, 4]. The largest square is always at one of the two ends of the original. Use a position at each end, compare their squares, write the larger into the last free slot of the result, and move that position inward. Fill the result from the back.

Write sorted_squares(nums) that returns a new sorted list of the squares. The point is to practise filling from both ends rather than call sort or sorted.

sorted_squares([-4, -1, 0, 3, 10])  ->  [0, 1, 9, 16, 100]
def sorted_squares(nums):
    ...