To get P , S , MR , and MC
for i in range ( len ( mat ) ) : NEW_LINE INDENT for j in range ( len ( mat [ 0 ] ) ) : NEW_LINE INDENT if i == j : NEW_LINE INDENT P . append ( mat [ i ] [ j ] ) NEW_LINE DEDENT if i + j == len ( mat ) - 1 : NEW_LINE INDENT S . append ( mat [ i ] [ j ] ) NEW_LINE DEDENT if i == ( len ( mat ) - 1 ) // 2 : NEW_LINE INDENT MR . append ( mat [ i ] [ j ] ) NEW_LINE DEDENT if j == ( len ( mat ) - 1 ) // 2 : NEW_LINE INDENT MC . append ( mat [ i ] [ j ] ) NEW_LINE DEDENT DEDENT DEDENT S . reverse ( ) NEW_LINE