I found the following code that is compatible with python2
from itertools import izip_longest
def grouper(n, iterable, padvalue=None):
\"grouper(3, \'abcde
In Python 3's itertools
there is a function called zip_longest
. It should do the same as izip_longest
from Python 2.
Why the change in name? You might also notice that itertools.izip
is now gone in Python 3 - that's because in Python 3, the zip
built-in function now returns an iterator, whereas in Python 2 it returns a list. Since there's no need for the izip
function, it also makes sense to rename the _longest
variant for consistency.