1

In this code the grouper function works fine, however if I do it without calling the function. It throws a error

TypeError: izip_longest argument #1 must support iteration

from itertools import *

def grouper(n, iterable, fillvalue=None):
    args = [iter(iterable)] * n
return izip_longest(fillvalue=fillvalue, *args)


x = [1,2,3]

args = [iter(x)] * 2
l = izip_longest(None , *args )
#l = grouper(2,x)
print [x for x in l]
4

1 回答 1

3

All positional arguments should be iterables, not fillvalue. Pass fillvalue as a keyword argument:

it = izip_longest(*iterables, fillvalue=None)

If fillvalue is None; you could omit it:

it = izip_longest(*iterables)
于 2013-03-29T21:05:33.103 回答