Вот один из способов сделать это:
a = int(input()) # Swap index
cl = 4 # Amount of columns
l = [1, 2, 3, 4,
5, 6, 7, 8,
9, 10, 11, 12,
13, 14, 15, 16,
17, 18, 19, 20,
21, 22, 23, 24]
l2 = l.copy()
for i,v in enumerate(l):
if i in range(a,len(l),cl*2):
l2[i] = l[i+cl]
l2[i+cl] = l[i]
l2[i+1] = l[i+cl+1]
l2[i+cl+1] = l[i+1]
print(l2)
Ввод:
0
Выход:
[5, 6, 3, 4,
1, 2, 7, 8,
13, 14, 11, 12,
9, 10, 15, 16,
21, 22, 19, 20,
17, 18, 23, 24]
Вход:
1
Вывод:
[1, 6, 7, 4,
5, 2, 3, 8,
9, 14, 15, 12,
13, 10, 11, 16,
17, 22, 23, 20,
21, 18, 19, 24]
Вход:
2
Вывод:
[1, 2, 7, 8,
5, 6, 3, 4,
9, 10, 15, 16,
13, 14, 11, 12,
17, 18, 23, 24,
21, 22, 19, 20]