from bisect import bisect_left
from typing import List


def find_nearest_wavelength( sorted_wavelengths: List[ float ], wavelength: float ) -> float:
    """
    Finds the value of the nearest wavelength in the sorted list sorted_wavelengths.

    :param sorted_wavelengths: List of wavelengths to parse
    :type sorted_wavelengths: list
    :param wavelength: Value of interest
    :type wavelength: float
    :return: Nearest value to wavelength contained withiin sorted_wavelengths
    :rtype: float
    """

    pos = bisect_left( sorted_wavelengths, wavelength )
    if pos == 0:
        return sorted_wavelengths[ 0 ]
    if pos == len( sorted_wavelengths ):
        return sorted_wavelengths[ -1 ]
    before = sorted_wavelengths[ pos - 1 ]
    after = sorted_wavelengths[ pos ]
    if after - wavelength < wavelength - before:
        return after
    else:
        return before