Converting from list of tuples to list of lists of tuples
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://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>
</blockquote>



<p>I have list of tuples, each tuple has two items (the amount of tuples may vary).</p>

<pre><code>[(a, b), (c, d)...)]
</code></pre>

<p>I want to convert the list to a nested list of tuples so that each nested list contains 4 tuples, if the original list of tuples has quantity not divisible by 4 e.g. 13 then the final list should contain the leftover amount in the case of 13, 1 tuple.</p>

<pre><code>[[(a, b), (c, d), (e, f), (g, h)], [(a, b), (c, d), (e, f), (g, h)]...]
</code></pre>

<p>One of the things about python I love is the methods and constructs for converting between different data structures, I was hoping there might be such a method or construct  for this problem that would be more pythonic then what Iv come up with.</p>

<pre><code>    image_thumb_pairs = [(a, b), (c, d), (e, f), (g, h), (i, j)]
    row = []
    rows = []
    for i, image in enumerate(image_thumb_pairs):
        row.append(image)
        if(i+1) % 4 == 0:
            rows.append(row)
            row = []
    if row:
        rows.append(row) 
</code></pre>
