title: Python - Deleting slices from files with ID
body: <p>Example: I have a file (1.txt) and the following content:</p>
  
  <pre><code>1 - a
  2 - ERROR
  3 - b
  4 - ERROR
  5 - c
  6 - ERROR
  7 - d
  8 - ERROR
  </code></pre>
  
  <p>and I'd like to create a new_1.txt with:</p>
  
  <pre><code>1 - a
  5 - c
  </code></pre>
  
  <p>As you can see I have the ERROR word as ID, what means: Always that Python finds the word 'ERROR', it will look for another 'ERROR' word and delete the slice of lines in the file. And so on until the end of the file. So the lines from 2 to 4 will be deleted, and the lines from 6 to 8 as well.</p>
  
  <p>My code is just deleting the lines that contains the word ERROR, but I need to delete the slices.</p>
  
  <pre><code>bad_words = "ERROR"
  with open("1.txt") as oldfile, open("new_1.txt", 'w') as newfile:
     for line in oldfile:
         if not any(bad_word in line for bad_word in bad_words):
             newfile.write(line)
  </code></pre>
  
  <p>I really appreciate your answers! </p>