def grouper(n, iterable, fillvalue=None):
      "grouper(3, 'abcdefg', 'x') --> abc def gxx"
      args = [iter(iterable)] * n
      kwds = dict(fillvalue=fillvalue)
      return izip_longest(*args, **kwds)

[GvR]
If you reverse the two parts it will work:

 izip_longest(fillvalue=fillvalue, *args)

Wow, I'm astonished that that works.  How weird.

Am I the only one who didn't know you could
put keyword arguments before star-args?

It's especially odd given that keyword arguments
are prohibited from preceding positional arguments, so
you can't just take the star-args version and
substitute the unpacked values:

IDLE 2.6b2
from itertools import izip_longest
args = 'abcdef', 'AB'
list(izip_longest(fillvalue='x', *args))
[('a', 'A'), ('b', 'B'), ('c', 'x'), ('d', 'x'), ('e', 'x'), ('f', 'x')]
list(izip_longest(fillvalue='x', 'abcdef', 'AB'))
SyntaxError: non-keyword arg after keyword arg


Raymond
_______________________________________________
Python-3000 mailing list
Python-3000@python.org
http://mail.python.org/mailman/listinfo/python-3000
Unsubscribe: 
http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com

Reply via email to