# warning - this code has never been run. Also there are probably # slighlty more succinct ways or doing this. The key point is that # more looping is necessary because we can't make the broadcasting do # looping for us. def non_numpy_iterate(board): neighbour_count = {} m, n = max(board) directions = ([(0, i) for i in (-1, 1)] + [(i, j) for i in (-1, 1) for j in (-1, 1)] + [(i, 0) for i in (-1, 1)]) for x, y in directions: for i in range(max(0, x), min(m, m + x)): for j in range(max(0, y), min(n, n - y)): neighbour_count.setdefault((i, j), 0) neighbour_count[i, j] += board[i, j] new_board = {} for i, j in board: state = (board[i, j] and (1 < neighbour_count[i, j] < 4) or not board[i, j] and neighbour_count[i, j] == 3) new_board[i, j] == int(state) return new_board