Given a rectangular matrix. To sort each column with an even number in ascending order. How can I do it?

The code below should output the matrix of n with even-numbered columns, and it displays only one row with an even index elements:
import random

x = random.randint(2,7)
y = x + random.randint(2,5)
a = [[random.randint(-10 , 10) for i in range(y)] for j in range(x)]


n = []

for i in a:
 for j in i:
 print("{:4d}".format(j), end=' ')
print()

for i in a:
 for j in i:
n.append(i[::2])


print(n)
March 23rd 20 at 19:26
1 answer
March 23rd 20 at 19:28
It outputs a matrix to a string. Run it again. You have everything working correctly

Here is an example of output for the last print:
[[4, 3, 6, -2, -6], [4, 3, 6, -2, -6], [4, 3, 6, -2, -6], [4, 3, 6, -2, -6] ... [4, 3, 6, -2, -6]]

Find more questions by tags Python