Can someone explain to me how to shorten this code like with a for loop or something? The if statement doesn’t change completely, just the "+" and "-".
# "+" and "-" changes
if (y[0] + 1, y[1]) in p:
x.append((y[0] + 1, y[1]))
p.remove((y[0] + 1, y[1]))
if (y[0] - 1, y[1]) in p:
x.append((y[0] - 1, y[1]))
p.remove((y[0] - 1, y[1]))
...
>Solution :
for delta in (-1, 1):
if (y[0] + delta, y[1]) in p:
x.append((y[0] + delta, y[1]))
p.remove((y[0] + delta, y[1]))