open input txt readlines list map int strip for in range len map int i

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
f = open("input.txt",'r')
f = f.readlines()
f = [list(map(int,f[i].strip())) for i in range(len(f))]
x,y = map(int,input().split())
x_i,y_j = map(int,input().split())
x_i2,y_j2 = map(int,input().split())
def Print(a):
for i in range(len(a)):
for j in range(len(a[i])):
print("%4d"%a[i][j],end = '')
print()
a = [[-1]*(y+2) for i in range(x+2)]
b = [[-1,0],[0,-1],[1,0],[0,1]]
for i in range(len(f)):
s = [-1]
for j in range(len(f[i])):
if f[i] == 1:s.append(-1)
else: s.append(0)
a[i+1] = s+[-1]
a[i+1] = [-1] + f[i] + [-1]
def move(a,x_i,y_j,d):
a[x_i][y_j] = d
if x_i == x_i2 and y_j == y_j2:
return a
else:
for i in range(4):
if a[x_i+b[i][0]][y_j+b[i][1]] == 0:
return move(a,x_i+b[i][0],y_j+b[i][1],d+1)
a[x_i][y_j] = 0
a = move(a,x_i,y_j,1)
if a != None:
Print(a)
else : print('The move can not to de done')