def neighbours_alive_count(grid, row, col):
    """ Takes a grid and a position and returns
    the number of living neighbour cells."""
    rows = range(max(0, row - 1), min(len(grid) - 1, row + 1) + 1)
    cols = range(max(0, col - 1), min(len(grid[0]) - 1, col + 1) + 1)
    return len([1 for x in cols for y in rows
        if grid[y][x] == 1 and (x, y) != (col, row)])