Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Moore Neighbourhood by a691662
def count_neighbours(grid, row, col):
lst = []
for rw in range(row-1,row+2):
for cl in range(col-1,col+2):
if 0 <= rw <= len(grid)-1 and 0 <= cl <= len(grid[0])-1 and [rw, cl] != [row, col]:
lst.append(grid[rw][cl])
return lst.count(1)
Jan. 29, 2015
Comments: