I want to print all the neigbours of a 2 dimensional array. For that I found this pseudocode but have problems translating it into python.
Can someone explain what does max() and min() are supposed to do? I think it's a range but not sure
row_limit = count(array);
if(row_limit > 0){
column_limit = count(array[0]);
for(x = max(0, i-1); x <= min(i+1, row_limit); x++){
for(y = max(0, j-1); y <= min(j+1, column_limit); y++){
if(x != i || y != j){
print array[x][y];
}
}
}
}
This is what I have so far:
def surrounded(board, row, col):
row_limit = len(board);
if row_limit > 0:
column_limit = len(board[0]);
for x in range(0, row-1):
if x <= min(row+1, row_limit):
for y in range(0, col-1):
if x <= min(j+1, column_limit):
if x != row and y != col:
print board[row][col];