title: How to iterate over a list in chunks
body: <p>I have a Python script which takes as input a list of integers, which I need to work with four integers at a time.  Unfortunately, I don't have control of the input, or I'd have it passed in as a list of four-element tuples.  Currently, I'm iterating over it this way:</p>
  <pre><code>for i in range(0, len(ints), 4):
      # dummy op for example code
      foo += ints[i] * ints[i + 1] + ints[i + 2] * ints[i + 3]
  </code></pre>
  <p>It looks a lot like &quot;C-think&quot;, though, which makes me suspect there's a more pythonic way of dealing with this situation.  The list is discarded after iterating, so it needn't be preserved.  Perhaps something like this would be better?</p>
  <pre><code>while ints:
      foo += ints[0] * ints[1] + ints[2] * ints[3]
      ints[0:4] = []
  </code></pre>
  <p>Still doesn't quite &quot;feel&quot; right, though.  :-/</p>
  <p>Related question: <a href="https://stackoverflow.com/questions/312443/how-do-you-split-a-list-into-evenly-sized-chunks-in-python">How do you split a list into evenly sized chunks in Python?</a></p>