Vector sorting
Create a function that takes a vector of numbers as input and returns a new vector containing the same numbers sorted in ascending order.
Here, a vector is a one-dimensional Python list of finite numbers. Preserve repeated values and leave the input list unchanged. An empty list returns a new empty list.
Complete the supplied function in Listing 1. Keep its signature and use the checks below it.
def sort_vector(vector: list[float]) -> list[float]:
# Add code here!
pass
def test_sort_vector() -> None:
# Input list
vector = [3, 1, 2, 5, 4]
sorted_vector = sort_vector(vector)
assert sorted_vector[0] == 1
assert sorted_vector[1] == 2
assert sorted_vector[2] == 3
assert sorted_vector[3] == 4
assert sorted_vector[4] == 5
test_sort_vector()
TipHint
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.