grouper(3, 'ABCDEFG', 'x') --> ABC DEF Gxx
(n, iterable, fillvalue=None)
| 200 | |
| 201 | |
| 202 | def grouper(n, iterable, fillvalue=None): |
| 203 | '''grouper(3, 'ABCDEFG', 'x') --> ABC DEF Gxx''' |
| 204 | args = [iter(iterable)] * n |
| 205 | if PY3: |
| 206 | output = it.zip_longest(fillvalue=fillvalue, *args) |
| 207 | else: |
| 208 | output = it.izip_longest(fillvalue=fillvalue, *args) |
| 209 | return output |
| 210 | |
| 211 | def mosaic(w, imgs): |
| 212 | '''Make a grid from images. |