import typing


def lightness(pixel: typing.Tuple[int, int, int]) -> float:
    """Sort by the lightness of a pixel according to a HLS representation."""
    # taken from rgb_to_hls
    r, g, b = pixel[:3]
    maxc = max(r, g, b)
    minc = min(r, g, b)
    return (minc + maxc) / 2.0