Python: split a list of n elements in a list of lists with n / x elements each
<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 a list of n elements and I want to split them evenly into sub-lists.</p>

<p>Desired interaction</p>

<pre>
>>>func([1, 2, 3, 4, 5, 6, 7, 8, 9], 3)
[[1,2,3], [4,5,6], [7,8,9]]
</pre>

<p>I would just assume x divides into n evenly.</p>

<p>Fastest way to do this? My current version is as follows:</p>

<pre>
def func(L, x):

    newL = []
    for i in range(len(L) // x):
        subL = []
        for j in range(x):
            subL.append(L.pop(0))
        newL.append(subL)
    return newL
</pre>
