自分用メモです。
問題:例外処理のタブーサーチ (paizaランク B 相当)
https://paiza.jp/works/mondai/steinsgate/restore_command_boss
最初に書いたコード
firsttry.py
n, m, l = map(int, input().split())
d = [[int(x) for x in input().split()] for y in range(n)]
p = [[int(x) for x in input().split()] for y in range(l)]
dif = []
for i in range(l-1):
difl = []
for j in range(m):
difl.append(p[i+1][j]-p[i][j])
dif.append(difl)
for difi in dif:
for i, di in enumerate(d):
if difi == di:
print(i+1)
difl配列を作らずに差分を求められそう
修正版
secondtry.py
n, m, l = map(int, input().split())
d = [[int(x) for x in input().split()] for y in range(n)]
p = [[int(x) for x in input().split()] for y in range(l)]
dif = [[p[i+1][j] - p[i][j] for j in range(m)] for i in range(l-1)]
for difi in dif:
for i, di in enumerate(d):
if difi == di:
print(i+1)
リスト内方表記をうまく利用することで一行で同じ処理ができたっぽい