title: Advanced (maybe) selection rule for lists in Python
body: <p>Given are a list</p>
  
  <pre><code>list_ = [a,a,b,b,b,a,b,a,b,b,...,b]
  </code></pre>
  
  <p>and two other lists</p>
  
  <pre><code>l_a = [v1,v2,...,vN]
  l_B = [w1,w2,...,wN].
  </code></pre>
  
  <p>The first element of list_ is always "<code>a</code>". The remaining elements can be mixed up between being "<code>a</code>" and "<code>b</code>" in any random way.</p>
  
  <p>Now, starting from the first element in list_ (which is always "a"):</p>
  
  <ol>
  <li>Take elements from <code>l_a</code> until you hit a "<code>b</code>" (in this case: [v1,
  v2]). Form "<code>v1+v2</code>" as a key for a dictionary (the corresponding value is in step 2. below). This is our current key.</li>
  <li>Take elements from l_b until you hit an "a" (in this case just [w1,w2,w3]). Store "<code>w1 + w2 + w3</code>" as value under the current key.</li>
  <li><em>Repeat</em>.</li>
  </ol>
  
  <p>Of course, there is a lot of loop stuff going on that I tried, but it just quickly gets difficult to bookkeep and makes me think there is a better way than nesting loops.</p>
  
  <p><strong>Question:</strong>
  So, simply put, how do I do this in an efficient way?</p>
  
  <p>Thank you</p>