Rotate matrix by 45 degrees | Function to rotate matrix by 45 degree ; Counter Variable ; Iterate [ 0 , m ] ; Iterate [ 0 , n ] ; Diagonal Elements Condition ; Appending the Diagonal Elements ; Printing reversed Diagonal Elements ; Dimensions of Matrix ; Given matrix ; Function Call
def matrix ( n , m , li ) : NEW_LINE INDENT ctr = 0 NEW_LINE while ( ctr < 2 * n - 1 ) : NEW_LINE INDENT print ( " ▁ " * abs ( n - ctr - 1 ) , end = " " ) NEW_LINE lst = [ ] NEW_LINE for i in range ( m ) : NEW_LINE INDENT for j in range ( n ) : NEW_LINE INDENT if i + j == ctr : NEW_LINE INDENT lst . append ( li [ i ] [ j ] ) NEW_LINE DEDENT DEDENT DEDENT lst . reverse ( ) NEW_LINE print ( * lst ) NEW_LINE ctr += 1 NEW_LINE DEDENT DEDENT n = 8 NEW_LINE m = n NEW_LINE li = [ [ 4 , 5 , 6 , 9 , 8 , 7 , 1 , 4 ] , [ 1 , 5 , 9 , 7 , 5 , 3 , 1 , 6 ] , [ 7 , 5 , 3 , 1 , 5 , 9 , 8 , 0 ] , [ 6 , 5 , 4 , 7 , 8 , 9 , 3 , 7 ] , [ 3 , 5 , 6 , 4 , 8 , 9 , 2 , 1 ] , [ 3 , 1 , 6 , 4 , 7 , 9 , 5 , 0 ] , [ 8 , 0 , 7 , 2 , 3 , 1 , 0 , 8 ] , [ 7 , 5 , 3 , 1 , 5 , 9 , 8 , 5 ] ] NEW_LINE matrix ( n , m , li ) NEW_LINE