Solve problem "Swap the columns" online - Learn Python 3 - Snakify
Processing math: 100%

Swap the columns


Statement

Given two positive integers m and n, m lines of n elements, giving an m×n matrix A, followed by two non-negative integers i and j less than n, swap columns i and j of A and print the result.

Write a function swap_columns(a, i, j) and call it to exchange the columns.


In all the problems input the data using input() and print the result using print().

# Read an integer:
# a = int(input())
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Input:
3 4
11 12 13 14
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Output:
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Saved solutions

Tests

InputCorrect answer
3 4
11 12 13 14
21 22 23 24
31 32 33 34
0 1
12 11 13 14
22 21 23 24
32 31 33 34
2 2
1 2
3 4
0 1
2 1
4 3
10 1
1
2
3
4
5
6
7
8
9
10
0 0
1
2
3
4
5
6
7
8
9
10
4 3
1 2 3
4 5 6
7 8 9
10 11 12
1 2
1 3 2
4 6 5
7 9 8
10 12 11
1 5
1 2 3 4 5
1 4
1 5 3 4 2
1 1
179
0 0
179
4 6
11 12 13 14 15 16
21 22 23 24 25 26
31 32 33 34 35 36
41 42 43 44 45 46
0 5
16 12 13 14 15 11
26 22 23 24 25 21
36 32 33 34 35 31
46 42 43 44 45 41
4 6
11 12 13 14 15 16
21 22 23 24 25 26
31 32 33 34 35 36
41 42 43 44 45 46
5 0
16 12 13 14 15 11
26 22 23 24 25 21
36 32 33 34 35 31
46 42 43 44 45 41
4 6
11 12 13 14 15 16
21 22 23 24 25 26
31 32 33 34 35 36
41 42 43 44 45 46
4 5
11 12 13 14 16 15
21 22 23 24 26 25
31 32 33 34 36 35
41 42 43 44 46 45
4 6
11 12 13 14 15 16
21 22 23 24 25 26
31 32 33 34 35 36
41 42 43 44 45 46
1 4
11 15 13 14 12 16
21 25 23 24 22 26
31 35 33 34 32 36
41 45 43 44 42 46
4 6
11 12 13 14 15 16
21 22 23 24 25 26
31 32 33 34 35 36
41 42 43 44 45 46
3 3
11 12 13 14 15 16
21 22 23 24 25 26
31 32 33 34 35 36
41 42 43 44 45 46