def normalise_array_index(index, length):
    """
    Normalises the given list index into the valid range for a
    list of the given length. This way negative indices index
    backward from the end of the list.

    :param index:   The index to normalise.
    :param length:  The list length to normalise to.
    :return:        The normalised index.
    """
    return index % length