title: Pythonic method to sum all the odd-numbered lines in a file
body: <p>I'm learning Python for a programming placement test I have to take for grad school, and this is literally the first little script I threw together to get a feel for it. My background is mainly C# and PHP, but I can't use either language on the test. </p>
  
  <p>My test script reads in the below text file (test_file1.txt). The even lines contain a sample size, and the odd lines contain "results" for each test in the sample. EOF is marked with a 0. I wanted to read in the file, output the sample size, and sum the results of each test. How would you perform this task with Python? I feel like I was trying to force python to be like PHP or C#, and from my research I guess there are very "Python" ways of doing thigs.</p>
  
  <p>test_file1.txt:</p>
  
  <pre><code>3
  13 15 18
  5 
  19 52 87 55 1
  4
  11 8 63 4
  2
  99 3
  0
  </code></pre>
  
  <p>My simple script:</p>
  
  <pre><code>file = open("test_file1.txt", "r")
  
  i=0
  for line in file:
      if i % 2 == 0:
          #num is even
          if line == '0':
              #EOF
              print 'End of experiment'   
      else:
          #num is odd
          numList = line.split( )
          numList = [int(x) for x in numList]
          print 'Sample size: ' + str(len(numList)) + ' Results: ' + str(sum(numList))
      i += 1
  
  file.close()
  </code></pre>
  
  <p>My results:</p>
  
  <pre><code>Sample size: 3 Results: 46
  Sample size: 5 Results: 214
  Sample size: 4 Results: 86
  Sample size: 2 Results: 102
  End of experiment
  </code></pre>
  
  <p>Thanks!</p>