title: Loop through generator two items at a time
body: <p>I have defined a generator that yields log entries from Elasticsearch:</p>
  
  <pre><code>def gen():
      ....
      for hit in results:
          yield hit
  </code></pre>
  
  <p>How can I loop through two elements at the same time? Something in the lines of:</p>
  
  <pre><code>for one, two in gen():
      ...
  </code></pre>
  
  <p>By two elements I mean this: <code>A, B</code>, <code>B, C</code>, ..., <code>Y, Z</code> (for a generated list of <code>A, B, ..., Y, Z</code>).</p>