title: can you use the del statement inside a for loop in python
body: <p>I want to remove the last two elements using the declaration of <code>del</code></p>
  <pre><code>Beatles = ['John Lennon', 'Paul McCartney', 'George Harrison', 'Stu Sutcliffe', 'Pete Best']
  for i in range(len(Beatles)):
      if Beatles[i] == 'Stu Sutcliffe' or Beatles[i] == 'Pete Best':
          print(i,Beatles[i]) #I print the index, to see if it is correct.
          del Beatles[i]
  print(&quot;List:&quot;, Beatles)
  </code></pre>
  <p>When I run it I get the following message:</p>
  <pre><code>if Beatles[i] == 'Stu Sutcliffe' or Beatles[i] == 'Pete Best':
  IndexError: list index out of range
  </code></pre>
  <p>It tells me that it is out of range, but it is strange since I visually validated that the index to be deleted is correct, I don't know if the instruction does not work inside the loop, since outside it works by passing the index [3] and [4].</p>
  <pre><code>del Beatles[3]
  del Beatles[4]
  </code></pre>