title: Separate odd and even lines in a generator with python
body: <p>I have a huge data file (~2 G) that needs to be splitted into odd and even lines, processed separately and written into two files, I don't want to read the whole file into RAM, so I think a generator should be a suitable choice. In short I want do something like this:</p>
  
  <pre><code>lines = (l.strip() for l in open(inputfn))
  oddlines = somefunction(getodds(lines))
  evenlines = somefunction(getevens(lines))
  outodds.write(oddlines)
  outevens.write(evenlines)
  </code></pre>
  
  <p>Is this possible? Apparently indexing will not work:</p>
  
  <pre><code>In [75]: lines[::2]
  ---------------------------------------------------------------------------
  TypeError                                 Traceback (most recent call last)
  /home/kaiyin/Phased/build37/chr22/segments/segment_1/&lt;ipython-input-75-97be680d00e3&gt; in &lt;module&gt;()
  ----&gt; 1 lines[::2]
  
  TypeError: 'generator' object is not subscriptable
  </code></pre>