from numpy import *
def isValid(grid):
count = 0
for x in range(0,9):
for y in range(0,9):
if grid[x][y] == 0:
# tell it to skip rest of code in function and keep going through for loop
a, b = x, y
x = 0
for i in range(0,9):
if grid[a][b] == grid[x+i][b]:
count += 1
if count != 1:
return 2
count = 0
return 1
you are reassigning the loop variable withing the loop...which is the reason for ur infinite loop