Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from collections import namedtuple
- from itertools import product
- Cell = namedtuple('Cell', ['x', 'y'], verbose=True)
- def get_neighbors(coordinate):
- row = ord(coordinate[0])
- col = int(coordinate[1:])
- coordinates = [Cell(x, y) for x, y in product(range(-1, 2), range(-1, 2))]
- coordinates = [cell for cell in coordinates if cell != Cell(0, 0)]
- coordinates = [Cell(row + cell.x, col + cell.y) for cell in coordinates]
- coordinates = [cell for cell in coordinates if ord('A') <= cell.x <= ord('Y')]
- coordinates = [cell for cell in coordinates if 0 <= cell.y <= 24]
- return [f"{chr(cell.x)}{cell.y}" for cell in coordinates]
Add Comment
Please, Sign In to add comment