Shifts all columns leftward when an entire column becomes empty. >>> move_y([['-', 'A'], ['-', '-'], ['-', 'C']], 2) [['A', '-'], ['-', '-'], ['-', 'C']]
(matrix_g: list[list[str]], size: int)
| 194 | |
| 195 | |
| 196 | def move_y(matrix_g: list[list[str]], size: int) -> list[list[str]]: |
| 197 | """ |
| 198 | Shifts all columns leftward when an entire column becomes empty. |
| 199 | |
| 200 | >>> move_y([['-', 'A'], ['-', '-'], ['-', 'C']], 2) |
| 201 | [['A', '-'], ['-', '-'], ['-', 'C']] |
| 202 | """ |
| 203 | |
| 204 | empty_columns = [] |
| 205 | |
| 206 | for column in range(size - 1, -1, -1): |
| 207 | if all(matrix_g[row][column] == "-" for row in range(size)): |
| 208 | empty_columns.append(column) |
| 209 | |
| 210 | for column in empty_columns: |
| 211 | for col in range(column + 1, size): |
| 212 | for row in range(size): |
| 213 | matrix_g[row][col - 1] = matrix_g[row][col] |
| 214 | for row in range(size): |
| 215 | matrix_g[row][-1] = "-" |
| 216 | |
| 217 | return matrix_g |
| 218 | |
| 219 | |
| 220 | def play( |