2 n will be the number of iterations
for t in range ( 2 * n - 1 ) : NEW_LINE INDENT t1 = t NEW_LINE if ( t1 >= n ) : NEW_LINE INDENT mode += 1 NEW_LINE t1 = n - 1 NEW_LINE it -= 1 NEW_LINE lower += 1 NEW_LINE DEDENT else : NEW_LINE INDENT lower = 0 NEW_LINE it += 1 NEW_LINE DEDENT for i in range ( t1 , lower - 1 , - 1 ) : NEW_LINE INDENT if ( ( t1 + mode ) % 2 == 0 ) : NEW_LINE INDENT print ( ( mat [ i ] [ t1 + lower - i ] ) ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( mat [ t1 + lower - i ] [ i ] ) NEW_LINE DEDENT DEDENT DEDENT