title: Efficiently copying specific lines to another file (Python 3.3)
body: <p>How to copy all even lines from one file to a new file in Python?</p>
  
  <p>The even number is just an illustration when I want a very select though substantive number of lines copied from one file to another, but it should be good as an example.</p>
  
  <p>I use this, but it is very inefficient (it takes around 5 minutes):</p>
  
  <pre><code># foo.txt holds 200,000 lines with 300 values
  list = [0, 2, 4, 6, 8, 10..... 199996, 199998]
  newfile = open(savefile, "w")
  with open("foo.txt", "r") as file:
      for i, line in enumerate(file):
          if i in list:
              newfile.write(line)
  newfile.close()
  </code></pre>
  
  <p>I would also appreciate it if there's an explanation why this is so slow: reading line by line goes quickly (around 15 seconds), and is also advised by the manual.</p>
  
  <p><strong>EDIT:</strong> My apologies; I am not looking for specific odd/even examples; it is merely for the effect of how to deal with around 100k out of 200k values in no easy order. Is there no general solution to the I/O problem here other than finding more efficient ways to deal with odd/even? Again apologies for bringing it up.</p>