title: Python sum array of objects into objects
body: <p>I have a list (name=carpet) of objects type mini_carpet.
  Mini_carpet contains a list of objects called packages.
  Packages has various properties, the one interesting to me is nr_buys.</p>
  
  <p>What I want to do is to sum the various nr_buys that are within a mini_carpet, within a carpet.
  This is what I have done so far:</p>
  
  <pre><code>for d in range(0, carpet.__len__() - 1, +1):
  nr_total = sum(carpet[d].packages[i].nr_buys for i in carpet[d].packages)
  </code></pre>
  
  <p>This is giving me an error because list indices must be integers.
  Any help?</p>
  
  <p>Thanks! </p>