title: "list index out of range" when try to output lines from a text file using python
body: <p>I was trying to extract even lines from a text file and output to a new file. But with my codes python warns me "list index out of range". Anyone can help me? THANKS~</p>
  
  <p>Code:</p>
  
  <pre><code>f = open('input.txt', 'r')
  i = 0
  j = 0 
  num_lines = sum(1 for line in f)
  newline = [0] * num_lines
  print (num_lines)
  for i in range(1, num_lines):
      if i % 2 == 0:
          newline[i] = f.readlines()[i]
              print i, newline[i]
      i = i + 1
  f.close()
  f = open('output.txt', 'w')
  for j in range(0,num_lines):
      if j % 2 == 0:
          f.write(newline[j] + '\n')
      j = j + 1
  f.close()
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>17
  Traceback (most recent call last):
    File "./5", line 10, in &lt;module&gt;
      a = f.readlines()[1]
  IndexError: list index out of range
  </code></pre>