def result_field mine mine mine field for in range for in range row_di

 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
def result_field(mine):
n,m=mine[0][0], mine[0][1]
field = [[0 for x in range(n)] for y in range(n)]
row_dict = {}
col_dict = {}
#Create dict with all mine coordinates
for row in mine[1:]:
if row[0] not in row_dict:
row_dict[row[0]]=1
else:
row_dict[row[0]]+=1
if row[1] not in col_dict:
col_dict[row[1]]=1
else:
col_dict[row[1]]+=1
#Preprocess field for cells with exact mine coordinate
field[row[0]][row[1]]=-1
#Calculate cells with row coordinates
for i in row_dict:
for j in range(n):
field[i][j] += row_dict[i]
#Calculate cells with column coordinates
for i in range(n):
for j in col_dict:
field[i][j] += col_dict[j]
return field
mine = [[5,4],[2,3],[0,2],[1,4],[2,0]]
field = result_field(mine)
print(field)