Values not added to list in loop without constraints

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?

1 answer

  • answered 2021-11-23 01:56 Atma

    Thanks @Selcuk

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

How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum