diff options
author | Stan Seibert <stan@mtrr.org> | 2011-08-17 18:38:48 -0400 |
---|---|---|
committer | Stan Seibert <stan@mtrr.org> | 2011-08-17 18:38:48 -0400 |
commit | d971120b20b0ed74d14e735c3fa9f45110e1bbd5 (patch) | |
tree | a574f6751bfee4a5a8d57ea61a6b96aea1ba1879 | |
parent | 506bcfcf589c007fa899c4f83595dc3a788447b3 (diff) | |
download | chroma-d971120b20b0ed74d14e735c3fa9f45110e1bbd5.tar.gz chroma-d971120b20b0ed74d14e735c3fa9f45110e1bbd5.tar.bz2 chroma-d971120b20b0ed74d14e735c3fa9f45110e1bbd5.zip |
add grouper function from the itertools example
-rw-r--r-- | itertoolset.py | 5 |
1 files changed, 5 insertions, 0 deletions
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) |