Неудачные структуры данных, всё громоздкое.
Поле обязательно растёт каждый шаг - плохо.
from collections import Counter
def display(t, gen):
sz = 10
sz2 = sz * 2
space = [[" "] * sz2 for i in range(sz2)]
for x, y in gen:
if sz > x >= -sz <= y < sz:
space[y + sz][x + sz] = "()"
for row in space:
print(''.join(row))
print("{:>3n}".format(t), "--" * sz2)
def game_life(cells, generations):
gen = set((x, y) for y, row in enumerate(cells) for x, cell in enumerate(row) if cell)
for t in range(generations):
display(t, gen)
ngh = Counter((x + i, y + j) for x, y in gen for i in range(-1, 2) for j in range(-1, 2))
gen = set(xy for xy, cnt in ngh.items() if cnt == 3 or cnt == 4 and xy in gen)
# game_life([[1, 1, 1]], 5) # палка
# game_life([[1, 1], [1, 1]], 5) # квадрат
game_life([[1, 1, 1], [0, 0, 1], [0, 1, 0]], 40) # планер