def clip(n, start, stop=None):
    """Return n clipped to range(start,stop)."""
    if stop is None:
        stop = start
        start = 0
    if n < start:
        return start
    if n >= stop:
        return stop-1
    return n