def nrange(start, stop, step):
    """Returns the indices of n-grams in a context window. Works much like
    range(start, stop, step), but the stop index is inclusive, and indices are
    included only if the step can fit between the candidate index and the stop
    index.

    :param start: starting index
    :type start: int
    :param stop: stop index
    :type stop: int
    :param step: n-gram length
    :type step: int
    :return: n-gram indices from left to right
    :rtype: list of int
    """
    idx = start
    rng = []
    while idx + step <= stop + 1:
        rng.append(idx)
        idx += 1
    return rng
