-1
I have Input: 
[[0, 1, 2], [2, 0, 1], [1, 2, 0]]
[[1, 0, 2], [0, 2, 1], [2, 1, 0]]
[[1, 0, 2], [2, 1, 0], [0, 2, 1]]
[[2, 0, 1], [0, 1, 2], [1, 2, 0]]
[[1, 2, 0], [2, 0, 1], [0, 1, 2]]
[[0, 1, 2], [1, 2, 0], [2, 0, 1]]
[[0, 2, 1], [1, 0, 2], [2, 1, 0]]
[[0, 2, 1], [2, 1, 0], [1, 0, 2]]
[[1, 2, 0], [0, 1, 2], [2, 0, 1]] #Array

I want to output print on screen:
[[0, 1, 2], [1, 0, 2], [1, 0, 2]]
[[2, 0, 1], [0, 2, 1], [2, 1, 0]]
[[1, 2, 0], [2, 1, 0], [0, 2, 1]]
[[2, 0, 1], [1, 2, 0], [0, 1, 2]]
[[0, 1, 2], [2, 0, 1], [1, 2, 0]]
[[1, 2, 0], [0, 1, 2], [2, 0, 1]]
[[0, 2, 1], [0, 2, 1], [1, 2, 0]]
[[1, 0, 2], [2, 1, 0], [0, 1, 2]]
[[2, 1, 0], [1, 0, 2], [2, 0, 1]]

Ex:
A=[[[0, 1, 2], [2, 0, 1], [1, 2, 0]],
[[1, 0, 2], [0, 2, 1], [2, 1, 0]],
[[1, 0, 2], [2, 1, 0], [0, 2, 1]]]

I want write code PYTHON to A[0][1] swap A[1][0], A[0][2] swap A[2][0] and A[1][2] swap A[2][1]

Output: 
A=[[[0, 1, 2], [1, 0, 2], [1, 0, 2]],
[[2, 0, 1], [0, 2, 1], [2, 1, 0]],
[[1, 2, 0], [2, 1, 0], [0, 2, 1]]]

## Please help me!!! Thank you all so much!!!

Đăng Khoa
  • 13
  • 1
  • 2
  • add: Use programming language Python3 (the pure version without using any external packages like numpy, pandas, pytorch,…) to write program. – Đăng Khoa Mar 30 '20 at 06:17
  • Maybe you can take advantage from other answers like [Python Array Rotation](https://stackoverflow.com/questions/17350330/) or [Rotating a two-dimensional array in Python](https://stackoverflow.com/questions/8421337/). – U880D Mar 30 '20 at 09:28

3 Answers3

1

You can try:

>>> A=[[[0, 1, 2], [2, 0, 1], [1, 2, 0]],
... [[1, 0, 2], [0, 2, 1], [2, 1, 0]],
... [[1, 0, 2], [2, 1, 0], [0, 2, 1]]]

>>> transpose_data = map(list, zip(*A))
>>> for data in transpose_data:
...     print(data)
...
[[0, 1, 2], [1, 0, 2], [1, 0, 2]]
[[2, 0, 1], [0, 2, 1], [2, 1, 0]]
[[1, 2, 0], [2, 1, 0], [0, 2, 1]]
Harsha Biyani
  • 7,049
  • 9
  • 37
  • 61
0

You can use Numpy array:

import numpy as np
A = np.array(A)
np.flip(np.rot90(A, axes=(0,1)), axis=0)
Laurent GRENIER
  • 612
  • 1
  • 6
  • 13
  • Sorry, I forgot to write the article asking not to use an external library like numpy Thanks for reading my question – Đăng Khoa Mar 30 '20 at 06:22
0
A=[[[0, 1, 2], [2, 0, 1], [1, 2, 0]],
[[1, 0, 2], [0, 2, 1], [2, 1, 0]],
[[1, 0, 2], [2, 1, 0], [0, 2, 1]]]

rows = len(A)
cols = len(A[0])
B = []

for col in range(cols):
bb = []
for row in range(rows):
    bb.append(A[row][col])
B.append(bb)
nerdoar
  • 11
  • 2