title: List comprehensions splitting loop variable
body: <p>I am trying to find out if there is a way to split the value of each iteration of a list comprehension only once but use it twice in the output. </p>
  
  <p>As an example of the problem I am trying to solve is, I have the string:</p>
  
  <pre><code>a = "1;2;4\n3;4;5"
  </code></pre>
  
  <p>And I would like to perform this:</p>
  
  <pre><code>&gt;&gt;&gt; [(x.split(";")[1],x.split(";")[2]) for x in a.split("\n") if x.split(",")[1] != 5]
  [('2', '4'), ('4', '5')]
  </code></pre>
  
  <p>Without the need for running split three times. So something like this (Which is obviously invalid syntax but hopefully is enough to get the message across):</p>
  
  <pre><code>[(x[1],x[2]) for x.split(";") in a.split("\n") if x[1] != 5]
  </code></pre>
  
  <p>In this question I am <strong>not</strong> looking for fancy ways to get the 2nd and 3rd column of the string. It is just a way of providing a concrete example. I could for course for the example use:</p>
  
  <pre><code>[x.split(";")[1:3] for x in a.split("\n")]
  </code></pre>
  
  <p>The possible solutions I have thought of:</p>
  
  <ol>
  <li>Not use a list comprehension</li>
  <li>Leave it as is</li>
  <li>Use the <code>csv.DictReader</code>, name my columns and something like <code>StringIO</code> to give it the input.</li>
  </ol>
  
  <p>This is mostly something that would be a nice pattern to be able to use rather than a specific case so its hard to answer the "why do you want to do this" or "what is this for" kind of questions</p>
  
  <p><strong>Update:</strong> After being reading the solution below I went and ran some speed tests. And I found in my very basic tests that the solution provided was 35% faster than the naive solution above.</p>