title: for loop through stdin using previous item
body: <p>I would like to compare a line to the previous one without storing anything in memory (no dictionaries).</p>
  
  <p>Sample data:</p>
  
  <pre><code>a   2
  file    1
  file    2
  file    4
  for 1
  has 1
  is  2
  lines   1
  small   1
  small   2
  test    1
  test    2
  this    1
  this    2
  two 1
  </code></pre>
  
  <p>Pseudocode:</p>
  
  <pre><code>for line in sys.stdin:
      word, count = line.split()
      if word == previous_word:
          print(word, count1+count2)
  </code></pre>
  
  <p>I know I would use <code>enumerate</code> or <code>dict.iteritems</code> over an array but I can't on <code>sys.stdin</code>.</p>
  
  <p>Desired output:</p>
  
  <pre><code>a   2
  file    7
  for 1
  has 1
  is  2
  lines   1
  small   3
  test    3
  this    3
  two 1
  </code></pre>