Trying to program puzzle the change of elements in equivalent positions of two arrays of error

I'm trying to make a puzzle in which the image comes shuffled into pieces, and by clicking on two different pieces they change position, if the drawing is correct it goes to the next one.

However the problem is when I check if the puzzle was solved, the solution I tried to implement was to create a list that contained identifiers of sprites in their respective places if the image had already reassembled listaSolucao and one with the current positions of the identifiers of sprites matrizResDesenho, so when I change two sprites places in the list desenho their respective identifiers also change places in the list matrizResDesenho at the end if it is correct both lists will be identical and will exit the loop.

At first it works but after some exchanges of sprites the identifiers start to randomly exchange with each other or else they simply do not change, visually it works perfectly, but because of this error the list matrizResDesenho does not meet its function to be compared with the solution, even if the drawing is right on the screen.

I would like to know where my error is in the following code, and if there is another better method to get it done that I want.

I tried to compare sprites but it always returns false so it is not a viable method.

I thank those who read everything and help me.

    while(puzzleAtivo):
        deltaClique += deltatime 

        for x in range(4):
            for y in range(4):
                if (mouse.is_over_object(desenho[x][y])): # se o mouse estiver em cima da imagem

                    if (mouse.is_button_pressed(1) and deltaClique > 1): # se o mouse clicar na imagem
                        deltaClique = 0 # limite de tempo para clicar novamente

                        if(segurando): # checa se há um sprite sendo "segurado"

                            atualX, atualY = desenho[x][y].x, desenho[x][y].y #armazena as posicoes atuais do sprite


                            # inverte as posições dos sprites em si na tela
                            desenho[x][y].x = desenho[seguradoX][seguradoY].x 
                            desenho[x][y].y = desenho[seguradoX][seguradoY].y

                            desenho[seguradoX][seguradoY].x = atualX
                            desenho[seguradoX][seguradoY].y = atualY

                            auxRes = matrizResDesenho[seguradoX][seguradoY] #armazena o index do identificador do sprite que ja estava sendo "segurado"

                            # inverte os identificadores do sprite que acaba de ser clicado com o que ja estava sendo "segurado"
                            matrizResDesenho[seguradoX][seguradoY] = matrizResDesenho[x][y]

                            matrizResDesenho[x][y] = auxRes

                            segurando = False

                        else:

                            seguradoX , seguradoY = x,y #se ao clicar em uma imagem ainda nao houver sprite sendo segurado armazena o index desta que acaba de ser clicada
                            segurando = True



        if checaSolucao(solucao, matrizResDesenho):
            break ```
Author: Éder Garcia, 2019-06-29