Python - While-Loop until list is empty
<p>I'm working with Django and I have a queryset of objects that has been converted to a list (<code>unpaid_sales</code>). I'm executing a process that iterates through this list and operates on each item until either the list is empty, or a given integer (<code>bucket</code>) reaches zero.</p>

<p>This is how I set it up:</p>

<pre><code>while unpaid_sales:
    while bucket &gt; 0:
        unpaid_sale = unpaid_sales.pop(0)
        ...do stuff
</code></pre>

<p>In some cases, I am getting the following error: </p>

<blockquote>
  <p>pop from empty list</p>
</blockquote>

<p>What's wrong with my logic?</p>

<p>You should do a single loop: <code>while bucket&gt;0 and unpaid_sales</code>. Here, you are popping elements in the <code>bucket</code> loop, and then just just check that <code>bucket</code> is positive, but you do not check that <code>element_sales</code> still has elements in it.</p>

python