Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def reverse_rows(n):
- for i in range(n // 2):
- for j in range(n):
- yield (i, j), (n - 1 - i, j)
- def print_matrix(m):
- for row in m:
- print(row)
- def apply_swaps(matrix, swaps) -> None:
- for (i1, j1), (i2, j2) in swaps:
- matrix[i1][j1], matrix[i2][j2] = matrix[i2][j2], matrix[i1][j1]
- def test_works():
- A = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
- print_matrix(A)
- print()
- apply_swaps(A, reverse_rows(3))
- print_matrix(A)
- def main():
- n = int(input('n: '))
- for t1, t2 in reverse_rows(n):
- print(*t1, *t2)
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement