-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask06.py
More file actions
32 lines (24 loc) · 876 Bytes
/
task06.py
File metadata and controls
32 lines (24 loc) · 876 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# coding=utf-8
# В матрице a(n, m) поменять местами столбцы с минимальным и максимальным
# количествами четных элементов. Матрица — список списков.
# a[row][col]
def swap_min_max_cols(rows, cols, mat):
if cols <= 1:
return mat
# array of zeroes with len of rows
counters = []
while len(counters) < cols:
counters.append(0)
# count num even numbers
for x in range(cols):
for y in range(rows):
if mat[y][x] % 2 == 0:
counters[x] += 1
index_min = counters.index(min(counters))
index_max = counters.index(max(counters))
# swap
for y in range(rows):
temp = mat[y][index_min]
mat[y][index_min] = mat[y][index_max]
mat[y][index_max] = temp
return mat