Python: split list into chunks of defined size and fill up rest
<p>I want to split my list into rows that have all the same number of columns, I'm looking for the best (most elegant/pythonic) way to achieve this:</p>

<pre><code>&gt;&gt;&gt; split.split_size([1,2,3], 5, 0)
[[1, 2, 3, 0, 0]]

&gt;&gt;&gt; split.split_size([1,2,3,4,5], 5, 0)
[[1, 2, 3, 4, 5]]

&gt;&gt;&gt; split.split_size([1,2,3,4,5,6], 5, 0)
[[1, 2, 3, 4, 5], [6, 0, 0, 0, 0]]

&gt;&gt;&gt; split.split_size([1,2,3,4,5,6,7], 5, 0)
[[1, 2, 3, 4, 5], [6, 7, 0, 0, 0]]
</code></pre>

<p>That's what I came up with so far:</p>

<pre><code>def split_size(l, size, fillup):
    """
    splits list into chunks of defined size, fills up last chunk with fillup if below size
    """
    # len(l) % size or size
    # does i.e. size=5: 3-&gt;2, 4-&gt;1, 5-&gt;0
    stack = l + [fillup] * (size - (len(l) % size or size))
    result = []
    while len(stack) &gt; 0:
        result.append(stack[:5])
        del stack[:5]
    return result
</code></pre>

<p>I'm sure there must be some smarter solutions. Especially for the "inverse mod" part:
    len(l) % size or size
there <em>must</em> be a more readable way to do this, no?</p>
