I made a program that solves 4x4 sudoku using backtracking algorithm (the grid is split into 2 parts which are also split into 2 parts with 4 cells) , it has 3 functions, first prints the grid, second checks if a number can be placed into a cell, and main function (first 2 functions work as they are intended to).The program isn't working properly, I checked it on pythontutor and found out that it returns lists even though it shouldn't, for example a number is placed into the list, then a function calls itself and if some of the numbers can't be placed then the function returns, but it seems that it also returns the list.Here's the code.I know that this program has flaws and it isn't very efficient (I also know what to change), but it won't work because of the same reason.
def sudoku(array):
for x in range(2): #loop that iterates through 2 lists
for y in range(2): #loop that iterates through 2 lists inside lists from above
for z in range(4): #loop that iterates through each cell
if array[x][y][z] == 0: #if a cell is empty then we can write numbers in it
for t in range(1, 5): #loop used for writing numbers into the cells
array[x][y][z] = t #line that writes numbers into the cells
rec = check(x, y, z, t, array) #check if a number can be placed
if rec == False: #if it can then
g = sudoku(array) #call the function
if g == True: #if g returns true then a solution is found, stop the program
return True
elif g == False and t == 4: #if g returns false and no number can be written into the next cell, and all numbers were written into the current cell, then return
return False
elif rec == True and t == 4: #if a number cant be placed into the cell and none of the numbers are valid, then return
return False
print_grid(array) #when all loops finish then a solution is found, print the grid
return True #return
array = [[[0, 4, 0, 0], [0, 1, 3, 0]], [[0, 2, 4, 0], [0, 0, 1, 0]]]