First solution in Speedy category for Moore Neighbourhood by blabaster
def count_neighbours(grid, row, col):
I may be aware more than most users ...
that functions and method calls are expensive ...
or that the fastest data type is a tuple.
Guido Van Rosuum
return sum(sum(((0,) + l)[col:col + 3]) for l in (((0,),) + grid)[row:row + 3]) - grid[row][col]
Oct. 10, 2014