title: Fastest way to remove first and last lines from a Python string
body: <p>I have a python script that, for various reasons, has a variable that is a fairly large string, say 10mb long. This string contains multiple lines.</p>
  
  <p>What is the fastest way to remove the first and last lines of this string? Due to the size of the string, the faster the operation, the better; there is an emphasis on speed. The program returns a slightly smaller string, sans the first and last lines.</p>
  
  <p><code>'\n'.join(string_variable[-1].split('\n')[1:-1])</code> is the easiest way to do this, but it's extremely slow because the split() function copies the object in memory, and the join() copies it again.</p>
  
  <p>Example string:</p>
  
  <pre><code>*** START OF DATA ***
  data
  data
  data
  *** END OF DATA ***
  </code></pre>
  
  <p>Extra credit: Have this program not choke if there is no data in between; this is optional, since for my case there shouldn't be a string with no data in between.</p>