···11import fileinput
223344-def is_safe(row, x):
44+def is_safe(row, i):
55 """Helper function to read out-of-bounds tiles as safe."""
66- if x < 0 or x >= len(row):
77- return True
66+ if 0 <= i < len(row):
77+ return row[i]
8899- return row[x]
99+ return True
101011111212def predict_next_row(row):
1313 """Given a row, returns the predicted following row."""
1414- next_row = []
1515-1616- for i in range(len(row)):
1717- a, c = is_safe(row, i - 1), is_safe(row, i + 1)
1818- next_row.append(not (a ^ c))
1919-2020- return tuple(next_row)
1414+ return [not (is_safe(row, i-1) ^ is_safe(row, i+1)) for i in range(len(row))]
211522162317if __name__ == '__main__':