def neighbors (row, col, nrows, ncols):
    """Returns a list of `(r, c)` 4-neighbors (up, down, left, right) for
    `(row, col)`.

    Invalid neighbor coordinates outside the range row and column range
    `[0, nrows]` or `[0, ncols]`, respectively, will not be returned.
    """
    deltas = (-1, 0), (0, -1), (1, 0), (0, 1)
    valid  = lambda r, c: r in range(0, nrows) and c in range(0, ncols)
    return [ (row + r, col + c) for r, c in deltas if valid(row + r, col + c) ]