title: How to chunk a list in Python 3?
body: <p>I found the following code that is compatible with python2</p>
  
  <pre><code>from itertools import izip_longest
  def grouper(n, iterable, padvalue=None):
    "grouper(3, 'abcdefg', 'x') --&gt; ('a','b','c'), ('d','e','f'), ('g','x','x')"
    return izip_longest(*[iter(iterable)]*n, fillvalue=padvalue)
  </code></pre>
  
  <p>However, <strong>this isn't working with Python 3</strong>. I get the following error</p>
  
  <pre><code>ImportError: cannot import name izip_longest
  </code></pre>
  
  <p>Can someone help?</p>
  
  <p>I'd like to convert my list of <code>[1,2,3,4,5,6,7,8,9]</code> to <code>[[1,2,3],[4,5,6],[7,8,9]]</code></p>
  
  <h2>Edit</h2>
  
  <h3>Now Python3 compatible</h3>
  
  <p>Code below is adapted from the selected answer. Simply change name from <code>izip_longest</code> to <code>zip_longest</code>.</p>
  
  <pre><code>from itertools import zip_longest
  def grouper(n, iterable, padvalue=None):
    "grouper(3, 'abcdefg', 'x') --&gt; ('a','b','c'), ('d','e','f'), ('g','x','x')"
    return zip_longest(*[iter(iterable)]*n, fillvalue=padvalue)
  </code></pre>