From d971120b20b0ed74d14e735c3fa9f45110e1bbd5 Mon Sep 17 00:00:00 2001 From: Stan Seibert Date: Wed, 17 Aug 2011 18:38:48 -0400 Subject: add grouper function from the itertools example --- itertoolset.py | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'itertoolset.py') diff --git a/itertoolset.py b/itertoolset.py index a20d03b..314ba0b 100644 --- a/itertoolset.py +++ b/itertoolset.py @@ -1,6 +1,11 @@ from itertools import * import collections +def grouper(n, iterable, fillvalue=None): + "grouper(3, 'ABCDEFG', 'x') --> ABC DEF Gxx" + args = [iter(iterable)] * n + return izip_longest(fillvalue=fillvalue, *args) + def roundrobin(*iterables): """roundrobin('ABC', 'D', 'EF') --> A D E B F C""" pending = len(iterables) -- cgit