title: Delete Range of Lines in Iterative Process
body: <p>I have a kml data file (~160,000 lines).  Within a Python script, I need to search for a keyword 'Unmatched' in the <code>&lt;name&gt;</code> tag and if found, remove everything from the <code>&lt;Placemark&gt;</code> to <code>&lt;/Placemark&gt;</code> associated with that named entry.</p>
  
  <p>I have tried the forums here and for a one time shot, it works, but when i need to perform this operation hundreds of times within the same file, I have not succeeded. There are 34 lines that need to be removed. 'prev' gets the starting line of where the delete needs to start and 'end' is where it stops... so I need to delete [prev:end] and then write those changes.</p>
  
  <pre><code>#!/usr/bin/python
  lookup = 'Unmatched '
  with open('doc.kml') as myFile:
      for num, line in enumerate(myFile, 1):
          if lookup in line:
              print 'Found in Line:', num
              prev = num-1
              print 'Placemark Starts at line:', prev
              end = prev+33
              print '/Placemark Ends at line:', end
  </code></pre>