The grouper
example in the itertools
recipes section should help you here:
http://docs.python.org/library/itertools.html#itertools-recipes
from itertools import zip_longest
def grouper(iterable, n, fillvalue=None):
"Collect data into fixed-length chunks or blocks"
# grouper('ABCDEFG', 3, 'x') --> ABC DEF Gxx"
args = [iter(iterable)] * n
return zip_longest(*args, fillvalue=fillvalue)
You would then it use like this:
for x, y in grouper(my_set, 2, 0.0): # Use 0.0 to pad with a float
print(x, y)