Modify a matrix by rotating ith row exactly i times in clockwise direction | Function to rotate every i - th row of the matrix i times ; Traverse the matrix row - wise ; Reverse the current row ; Reverse the first i elements ; Reverse the last ( N - i ) elements ; Increment count ; Print final matrix ; Driver Code
def rotateMatrix ( mat ) : NEW_LINE INDENT i = 0 NEW_LINE mat1 = [ ] NEW_LINE for it in mat : NEW_LINE INDENT it . reverse ( ) NEW_LINE it1 = it [ : i ] NEW_LINE it1 . reverse ( ) NEW_LINE it2 = it [ i : ] NEW_LINE it2 . reverse ( ) NEW_LINE i += 1 NEW_LINE mat1 . append ( it1 + it2 ) NEW_LINE DEDENT for rows in mat1 : NEW_LINE INDENT for cols in rows : NEW_LINE INDENT print ( cols , end = " ▁ " ) NEW_LINE DEDENT print ( ) NEW_LINE DEDENT DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT mat = [ [ 1 , 2 , 3 ] , [ 4 , 5 , 6 ] , [ 7 , 8 , 9 ] ] NEW_LINE rotateMatrix ( mat ) NEW_LINE DEDENT