title: Why Python Decimal sum is not commutative (different result when I change the order)
body: <p><strong>I am using Decimal with strings to avoid the typical problem</strong></p>
  <p>I have two dictionaries that have the same keys and values but with the keys in a different order. <strong>The sum of the values of these dictionaries should be zero</strong>. However, it is not zero when I sum them in a certain order.</p>
  <p>These are my dictionaries and the comparisons I made to make sure the values are the same:</p>
  <pre class="lang-py prettyprint-override"><code>a = {'key_A': Decimal('0'),
      'key_B': Decimal('-1002708'),
      'key_C': Decimal('3965.5752'),
      'key_D': Decimal('991393.8'),
      'key_E': Decimal('-991393.8'),
      'key_F': Decimal('1173.30984201680672268907563'),
      'key_G': Decimal('-7348.6248'),
      'key_H': Decimal('6175.31495798319327731092437'),
      'key_I': Decimal('-741'),
      'key_J': Decimal('0'),
      'key_K': Decimal('4641'),
      'key_U': Decimal('-3900'),
      'key_L': Decimal('1038000'),
      'key_M': Decimal('0'),
      'key_N': Decimal('0'),
      'key_O': Decimal('0'),
      'key_P': Decimal('-3965.5752'),
      'key_Q': Decimal('0'),
      'key_R': Decimal('0'),
      'key_S': Decimal('-15570'),
      'key_T': Decimal('-19722')}
  
  b = {'key_C': Decimal('3965.5752'),
      'key_D': Decimal('991393.8'),
      'key_B': Decimal('-1002708'),
      'key_K': Decimal('4641'),
      'key_U': Decimal('-3900'),
      'key_J': Decimal('0'),
      'key_A': Decimal('0'),
      'key_G': Decimal('-7348.6248'),
      'key_H': Decimal('6175.31495798319327731092437'),
      'key_I': Decimal('-741'),
      'key_R': Decimal('0'),
      'key_N': Decimal('0'),
      'key_T': Decimal('-19722'),
      'key_P': Decimal('-3965.5752'),
      'key_M': Decimal('0'),
      'key_L': Decimal('1038000'),
      'key_F': Decimal('1173.30984201680672268907563'),
      'key_O': Decimal('0'),
      'key_Q': Decimal('0'),
      'key_E': Decimal('-991393.8'),
      'key_S': Decimal('-15570')}
  
  print(sorted(list(a.keys()))==sorted(list(b.keys()))) # &quot;True&quot; so the keys are the same
  
  print(len(a), len(b)) # &quot;21 21&quot; the length are the same
  
  
  keys = sorted(list(a.keys()))
  for k in keys:
   assert a[k]==b[k] # never throws exception so the values are the same
  
  sum_d = lambda d: sum(d[key] for key in d) # a function that sums all the values in a dictionary
  </code></pre>
  <p><strong>HERE IS THE PROBLEM:</strong></p>
  <pre class="lang-py prettyprint-override"><code>print(sum_d(a), sum_d(b)) # &quot;4E-22 0E-21&quot; EVEN WHEN THE VALUES ARE THE SAME THE SUMS ARE NOT WTF
  </code></pre>
  <p><strong>HERE IS WHEN IT GETS EVEN WEIRDER</strong>
  I wanted to make sure this was because of the order, so I inverted the order</p>
  <pre class="lang-py prettyprint-override"><code>a_new = {key:a[key] for key in b.keys()}
  b_new = {key:b[key] for key in a.keys()}
    
  print(sum_d(a_new), sum_d(b_new)) # &quot;0E-21 4E-22&quot; THE VALUES INVERTED SO IT IS BECAUSE OF THE ORDER
  
  </code></pre>
  <p>So my question is just..... <em><strong>WHY...</strong></em> why python sum is not commutative?</p>