array def Search List value return List __contains__ value while in ar

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
array=[[0,2,0,0,4,0,0,5,0],[0,0,0,7,2,6,0,0,0],[0,0,7,0,9,0,6,0,0],
[7,0,8,0,5,0,2,0,6],[9,0,0,0,0,0,0,0,4],[5,0,1,0,8,0,7,0,9],
[0,0,6,0,1,0,8,0,0],[0,0,0,8,7,3,0,0,0],[0,7,0,0,6,0,0,4,0]]
def Search(List,value):
return List.__contains__(value)
while(0 in [array[i][j] for i in range(9) for j in range(9)]):
for i in range(1,10):
for j in range(9):
count=0;
for k in range(9):
if(array[j][k] ==0):
A=[array[j][l] for l in range(9)];
B=[array[l][k] for l in range(9)];
C=[array[l][m] for l in range((j-j%3),(j-j%3)+3) for m in range((k-k%3),(k-k%3)+3) ];
if(not Search(A,i) and not Search(B,i) and not Search(C,i)):
count,row,column=count+1,j,k;
if(count==1):
array[row][column]=i;
for element in range(9):
print array[element];