title: Inline for loop
body: <p>I'm trying to learn neat pythonic ways of doing things, and was wondering why my for loop cannot be refactored this way:</p>
  
  <pre><code>q  = [1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5]
  vm = [-1, -1, -1, -1]
  
  for v in vm:
      if v in q:
          p.append(q.index(v))
      else:
          p.append(99999)
  
  vm[p.index(max(p))] = i
  </code></pre>
  
  <p>I tried replacing the for loop with:</p>
  
  <pre><code>[p.append(q.index(v)) if v in q else p.append(99999) for v in vm]
  </code></pre>
  
  <p>But it doesn't work. The <code>for v in vm:</code> loop evicts numbers from <code>vm</code> based on when they come next in <code>q</code>.</p>