Appending border elements
for i in range ( m ) : NEW_LINE INDENT for j in range ( n ) : NEW_LINE INDENT if j == n - 1 or ( i == m - 1 ) or j == 0 or i == 0 : NEW_LINE INDENT A . append ( grid [ i ] [ j ] ) NEW_LINE DEDENT DEDENT DEDENT