Modified from the recipes section of Python's itertools docs:
def grouper(iterable, n, fillvalue=None):
args =[iter(iterable)]* n
return izip_longest(*args, fillvalue=fillvalue)
Example
In pseudocode to keep the example terse.
grouper('ABCDEFG',3,'x')-->'ABC''DEF''Gxx'