Home > OS >  Values not added to list in loop without constraints
Values not added to list in loop without constraints

Time:11-27

I have the following loop:

deposits = Deposit.objects.all()

print('Processing ' str(len(deposits))  ' values . .  .')


deposit_values = {}

for d in deposits:
 
    bas = Account.objects.filter(
        pk=d.account.id,
        )
    
   
    if len(bas) == 1:
        ba = bas[0]
        deposit_values[ba.id] = d.amount
    else:
        print(ba.id)
   

print(' ')
print(str(len(deposit_values))  ' values processed.')

This prints the following output:

Processing 712 values . . . 710 values processed.

How is this possible when there are no constraints for values that go into deposit values?

CodePudding user response:

Thanks @Selcuk

there are deposits that have the same account id and you end up overwriting one with the other in your deposit_values

  • Related