too_big = False
for (x, y) in exp:
if (x > 7) or (y > 7) or (x < -7) or (y < -7):
too_big = True
break
if too_big:
continue
2.75) Don't add bad permutations
In the first for loop of possible_expansions, we can reject pieces that are too large:
for (x, y) in piece:
for dx, dy in neighbor_offsets:
if abs(x + dx) > 7 or abs(y + dy) > 7:
continue
positions.add((x + dx, y + dy))