Task def result_field mine mine field for in range for in range for ro

 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
33
34
35
36
37
38
39
40
41
42
43
#Task 1
def result_field(mine):
n,m=mine[0][0], a[0][1]
field = [[0 for x in range(n)] for y in range(n)]
for rows in mine[1:]:
row = rows[0]
col = rows[1]
for i in range(n):
field[row][i] +=1
if i != row:
field[i][col] += 1
return field
mine = [[5,4],[2,3],[0,2],[1,4],[2,0]]
field = result_field(mine)
field
#Task 2
matrix = [
[1,2,3],
[4,5,6],
[7,8,9]
]
def rotate(matrix) -> None:
"""
Do not return anything, modify matrix in-place instead.
"""
size = len(matrix)
for i in range(size):
for j in range(i, size):
t = matrix[i][j]
matrix[i][j] = matrix[j][i]
matrix[j][i]=t
for i in range(size):
for j in range(size//2):
t = matrix[i][j]
matrix[i][j] =matrix[i][size-j-1]
matrix[i][size-j-1] = t
rotate(matrix)
print(matrix)