title: What is the pythonic way of extracting (& removing) a slice from a list? Or... What is the "inverse" of the slice+=list operator - python
body: <p>I know how insert a list into a list, "slice+=list" ...</p>
  
  <pre><code>master=[0,1,2,3,7,8,9]
  master[:4]+=[4,5,6] # insert 4,5,6
  </code></pre>
  
  <p>(crudely) The inverse of this operation is removing a slice 4:7 from the list, I tried:</p>
  
  <pre><code>extracted=del master[4:7]
  </code></pre>
  
  <p>But this gives a syntax error "SyntaxError: invalid syntax".
  Likewise the inverse slice operator "-=" doesn't appear to exist.</p>
  
  <p>As a workaround I have used the following:</p>
  
  <pre><code>extracted=master[4:7]; del master[4:7]
  </code></pre>
  
  <p>This "works" and the "extracted" is the subslice removed from "master", e.g.</p>
  
  <pre><code>print dict(master=master,extracted=extracted)
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>{'extracted': [4, 5, 6], 'master': [0, 1, 2, 3, 7, 8, 9]}
  </code></pre>
  
  <p>Is there a better/pythonic/simpler way ?  </p>
  
  <p>In particular I don't like the repeated [4:7] in: </p>
  
  <pre><code>extracted=master[4:7]; del master[4:7]" 
  </code></pre>
  
  <p>Because of potential side-effects: eg </p>
  
  <pre><code>extracted=master[randint(0,3):randint(7,10)]; del master[randint(0,3):randint(7,10)]
  </code></pre>
  
  <p>i.e. the following reads much better, and would have no "side-effects"...</p>
  
  <pre><code>extracted=del master[randint(0,3):randint(7,10)] 
  </code></pre>
  
  <p>Any hints?  Is there a slice "-=" operator I could have used to invert the action of the slice "+=" operator?</p>