title: Splitting input into lines in python
body: <p>I am trying to solve this problem <a href="http://www.spoj.pl/problems/PEBBMOV/" rel="nofollow">http://www.spoj.pl/problems/PEBBMOV/</a>. I think I have the right algorithm, that is not the point of this question. This problem has a weird input file to it. The input for one test case should be of the form
  n a1 a2 a3 ...an. (all ints)</p>
  
  <p>The problem here is that , there are stray newline characters etc in between the a[i]s. I need to be able to skip such newlines and collect all a[i]s belonging to one test case at a place. How do I know all this? Well a string of WAs and Runtime Errors , plus some research on the forums. I have the following python code to try to do this, except that i seem to be faltering at crucial places and just cant get it done. I hope to have the appropriate input lines in the list lines[] at the end of the input reading. </p>
  
  <p>Could someone please tell me my mistake(s) here.? Or suggest a better approach?. Thanks in advance..</p>
  
  <pre><code>import sys
  #data = sys.stdin.readlines()
  #lines = inp.split('\n')
  data = sys.stdin.read()
  pos = 0
  lno = 0
  
  lines = []
  while pos&lt;len(data):
      while not data[pos].isdigit():
                     pos = pos + 1
  num =data[pos]
  print num
  cur = pos + 1
  numbers_collected = 0
  
  x = [] # temp list
  y = []
  while numbers_collected &lt; num:
  
      if cur&lt;len(data) and data[cur].isdigit():
          y.append(data[cur])
          cur = cur + 1
          numbers_collected += 1
      else:
          if cur&lt;len(data)and numbers_collected &lt; num:
              cur = cur + 1
          else:
              break
  print x
  pos = cur
  x.extend(y)
  lines.extend(x)
  
  
  
  for line in lines:
      print line
  </code></pre>