title: Python trying to remove all occurences of an element in an array with a for loop
body: <p>I'm trying to remove all elements whose text property is equal to &quot;PayLivery&quot; from an array called &quot;prices&quot;.</p>
  <p>I'm new to python and don't understand why this code doesn't work:</p>
  <pre class="lang-py prettyprint-override"><code>for i in range(len(prices)):
      if prices[i].text == &quot;PayLivery&quot;:
          prices.pop(i)
          i-=1
  </code></pre>
  <p>The array(prices) has a length of 37 at the beginning. It throws a &quot;Index Error list index out of range&quot; error at an i value of 25 and a (prices)length of 25.</p>
  <p>I hope someone can help me. Thanks in advance.</p>