title: Python - Reading pairs of lines in a file
body: <p>I am wanting to read pairs of lines in from a file, and perform operations on them. How do I go about doing this in Python?</p>
  
  <p>I can read the file once with the code below, but I don't know how to turn this into being able to read a whole file of lets say 20 lines, with the rest of my code having to operate on the 10 sets of data that the 20 line file has. There will always be an even amount of lines in the input file.</p>
  
  <pre><code>import sys
  input = sys.stdin
  favouriteNumbersInput = []
  
  with open("test.txt", 'r') as infile:
      lines_gen = islice(infile, 2)
      for line in lines_gen:
  
          favouriteNumbersInput.append(line.strip(' ').strip('\n'))
          firstName,lastName = map(str,line.split(" "))
          favouriteNumbers = list(map(int, favouriteNumbersInput))
  </code></pre>
  
  <p>Input:</p>
  
  <pre><code>3, 1, 5, 2
  John Doe
  5, 1, 6, 7
  Jane Doe
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>Sum of favourite numbers for John Doe: 11
  Sum of favourite numbers for Jane Doe: 19
  </code></pre>