File tree Expand file tree Collapse file tree 1 file changed +2
-42
lines changed
exercises/practice/flower-field Expand file tree Collapse file tree 1 file changed +2
-42
lines changed Original file line number Diff line number Diff line change 1- # def annotate(garden):
2- # # Function body starts here
3- # pass
41def annotate (garden ):
5- if not garden :
6- return []
7- verify_board (garden )
8- row_len = len (garden [0 ])
9- col_len = len (garden )
10- board = [list (row ) for row in garden ]
11-
12- for index1 in range (col_len ):
13- for index2 in range (row_len ):
14- if board [index1 ][index2 ] != ' ' :
15- continue
16-
17- low = max (index2 - 1 , 0 )
18- high = min (index2 + 2 , row_len + 2 )
19- counts = garden [index1 ][low :high ].count ('*' )
20-
21- if index1 > 0 :
22- counts += garden [index1 - 1 ][low :high ].count ('*' )
23- if index1 < col_len - 1 :
24- counts += garden [index1 + 1 ][low :high ].count ('*' )
25- if counts == 0 :
26- continue
27-
28- board [index1 ][index2 ] = str (counts )
29- return ['' .join (row ) for row in board ]
30-
31-
32- def verify_board (garden ):
33- # Rows with different lengths
34- row_len = len (garden [0 ])
35- if not all (len (row ) == row_len for row in garden ):
36- raise ValueError ('The board is invalid with current input.' )
37-
38- # Unknown character in board
39- character_set = set ()
40- for row in garden :
41- character_set .update (row )
42- if character_set - set (' *' ):
43- raise ValueError ('The board is invalid with current input.' )
2+ # Function body starts here
3+ pass
You can’t perform that action at this time.
0 commit comments