title: Extract subarray between certain value in Python
body: <p>I have a list of values that are the result of merging many files. I need to pad some of the values. I know that each sub-section begins with the value -1. I am trying to basically extract a sub-array between -1's in the main array via iteration.</p>
  <p>For example supposed this is the main list:</p>
  <pre><code>-1 1 2 3 4 5 7 -1 4 4 4 5 6 7 7 8 -1 0 2 3 5 -1
  </code></pre>
  <p>I would like to extract the values between the -1s:</p>
  <pre><code>list_a = 1 2 3 4 5 7
  list_b = 4 4 4 5 6 7 7 8
  list_c = 0 2 3 5 ...
  list_n = a1 a2 a3 ... aM
  </code></pre>
  <p>I have extracted the indices for each -1 by searching through the main list:</p>
  <pre><code>minus_ones = [i for i, j in izip(count(), q) if j == -1]
  </code></pre>
  <p>I also assembled them as pairs using a common recipe:</p>
  <pre><code>def pairwise(iterable):
      a, b = tee(iterable)
      next(b, None)
      return izip(a,b)
  
  for index in pairwise(minus_ones):
      print index
  </code></pre>
  <p>The next step I am trying to do is grab the values between the index pairs, for example:</p>
  <pre><code> list_b: (7 , 16) -&gt; 4 4 4 5 6 7 7 8 
  </code></pre>
  <p>so I can then do some work to those values (I will add a fixed int. to each value in each sub-array).</p>