Redimension dynamic vector

Create a function that takes a dynamic one-dimensional list as input and changes it in place to a new specified size. Preserve the existing data while changing the size. If the list grows, add 0.0 values; if it shrinks, remove values from the end.

Use a nonnegative integer new_size. The vector is a one-dimensional Python list. Keep the same list object, including when resizing to 0, and return None. A request for the current size leaves all values unchanged.

Complete the supplied function in Listing 1. Keep its signature and use the checks below it.

Listing 1: Starter function and supplied checks for redimension dynamic vector.
def redimension_dynamic_vector(
    dynamic_list: list[float], new_size: int
) -> None:
    # Add code here! Consider extend() when growing the list.
    pass


def test_redimension_dynamic_vector() -> None:
    # This starting list makes the exercise independent of an initializer.
    my_dynamic_list = [100, 200, 300]

    # Redimension the dynamic list to a new size.
    redimension_dynamic_vector(my_dynamic_list, 7)
    assert len(my_dynamic_list) == 7
    assert my_dynamic_list[:3] == [100, 200, 300]

    assert my_dynamic_list == [100, 200, 300, 0.0, 0.0, 0.0, 0.0]

    redimension_dynamic_vector(my_dynamic_list, 2)
    assert my_dynamic_list == [100, 200]


test_redimension_dynamic_vector()

len(values) returns the number of elements, so len([3, 7]) is 2 and len([]) is 0. List indexing starts at 0: [3, 7][0] is 3. An index must refer to an existing element.

assert condition stops the check with an AssertionError when the condition is false. values.extend(other) appends the elements of other to the existing list and returns None. For example, extending [1] with [2, 3] changes it to [1, 2, 3]. A slice values[start:] selects the elements from index start through the end; del values[start:] removes those elements in place.