title: Python 3: Checking next value of an iterator without iterating
body: <p>For a project I need to check in a csv file if the value in a certain column of the next row is equal to the value in the same column of the current row. I am using a dictionary csv reader, i.e. each row in the reader is a dictionary file. I can access a value of a certain row by using the column header as a key: <code>row[header] = value</code>.</p>
  
  <p>A stripped-down version of my current code looks like this:</p>
  
  <pre><code>import csv
  
  with open(os.path.abspath(path_to_file), "r") as f:
      reader = csv.DictReader(f, dialect='excel')
  
      for row in reader:
          current_row = row
          next_row = reader.__next__()
          if current_row[column] == next_row[column]:
              dosomething()
  </code></pre>
  
  <p>The problem here is of course that I skip the next iteration by using <code>__next__()</code>, i.e.</p>
  
  <p>(1) I enter the loop; row = row1
  (2) current_row = row1, next_row = row2
  (3) I enter the next iteration of the loop; row = row3 because I used <code>__next__()</code>. current_row = row3, next_row = row4</p>
  
  <p>In this example I would never check <code>row2 == row3</code>.</p>
  
  <p>Is it possible to check the values of the next row without iterating over the iterator object?
  Or, alternatively, is there an opposite methode to <code>__next__()</code>, which makes the iterator go back one step?</p>
  
  <p><strong>Please note</strong>: I'm comparing the <em>current</em> value to the next <em>value</em> instead of the <em>current</em> value to the <em>last</em> value because I don't know how long the file I'm reading is. I have to treat the last row of the file different from the others, so I have to check <code>reader.__next()__</code> anyway to see if there is a last line at all.</p>