from typing import List


def partition(A: List[float], left: int, right: int) -> int:
    """
    Swaps values such that all values on the left are less than or equal to the returned index and all values on the right are greater than the returned index.
    :param A: list/array to partition
    :param left: left index of the subarray to partition.
    :param right: right index of the subarray to partition.
    :return: integer index splitting the partitioned array
    """
    # Choose pivot value:
    pivot = A[int((left + right) / 2)]
    while left <= right:
        # Find elements to swap:
        while A[left] < pivot:
            left += 1
        while A[right] > pivot:
            right -= 1

        # Swap elements. Move left and right indices:
        if left <= right:
            tmp = A[left]
            A[left] = A[right]
            A[right] = tmp
            left += 1
            right -= 1
    return left