rows = 5 cols = 4 mat = [range(0 + (cols * i), cols + (cols * i), 1) for i in range(rows)] def print_mat(mat): for s in mat: print(*s) def rotate_mat(mat): mat = [[mat[row][col] for row in range(rows - 1, -1, -1)] for col in range(cols)] return mat print_mat(mat) mat = rotate_mat(mat) print("rotated:") print_mat(mat)