Created
January 21, 2015 03:12
-
-
Save 00krishna/8325cef32d1f53719d54 to your computer and use it in GitHub Desktop.
find adjacent cells in 2d grid
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_adjacent_cells( self, x_coord, y_coord ): | |
result = {} | |
for x,y in [(x_coord+i,y_coord+j) for i in (-1,0,1) for j in (-1,0,1) if i != 0 or j != 0]: | |
if (x,y) in grid.cells: | |
result[(x,y)] = grid.cells[(x,y)] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment