List getting empty after loop in python

0

Hello, I have the following code that does this: It will traverse a vector that has a certain sets of elements (remainder) with the same ID ([1] [1] [1] [2] [2] by example) and then store all elements of the same ID in separate vectors and then take these vectors (atoms of Anel) of elements and store them in a single vector (aneRes). The question is as follows, the vectors are stored correctly and if I give a print each time the loop rotates, it (aneisRes which is the final vector) prints correctly. However, if I give a print in the anisRes before the return (outside the loop) it prints empty. Does anyone know why? The two vectors (atoms of Ana and rings are of the class whose function is declared) Note: I am a beginner in python so sorry for anything strange in the code and any tips to improve it will be very welcome. Thanks

def preencheAnel(self,  residuo, tamanhoVetRes):

    i = 1
    cont = 0
    aux = 0
    totalSub = 0         

    #verifica qual a quantidade de elementos iguais há em um conjunto pois é a mesma quantidade para todos os outros conjuntos
    aux = residuo[cont][4]
    while (aux == residuo[i][4]) & (i < tamanhoVetRes):
        cont = cont + 1
        i = i + 1
        aux = residuo[cont][4]

    #armazena em um vetor todos os elementos de um mesmo grupo num vetor e depois armazena esse em outro vetor
    cont = cont+1
    aux = 0
    i = 1
    totalSub = tamanhoVetRes / cont
    while i <= totalSub:
        while aux < (cont*i):
            self.atomosDoAnel.append(residuo[aux])
            aux = aux + 1                       
        print(i, aux)
        i = i+1
        cont = cont + i +1
        self.aneisRes.append(self.atomosDoAnel)
        print(self.aneisRes,"\n") #Imprime
        del self.atomosDoAnel[:]    

    print(self.aneisRes,"\n") #Não Imprime
    return(self.aneisRes)   
    
asked by anonymous 07.04.2017 / 06:26

1 answer

0

The problem is in the self.atomosDoAnel [:], aux reaches the value greater than (cont i) and loop while aux < (cont i) is no longer executed, self.aneisRes.append (self.atomosDoAnel) continues adding self.atomosDoAnel which is an empty list. To fix this you need to add aux = 0 inside the loop while i

07.04.2017 / 09:35