You need a function to group a sequence into fixed-length chunks. Unfortunately, this is lacking from the Python core. You could use partition from the funcy library. (Side note: In other languages this is called chunksOf or grouped).
The itertools documentation suggests this function:
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)
And the zip documentation suggests a different way to accomplish the same thing (given in gnibbler's answer):
def grouper(iterable, n):
return zip(*[iter(iterable)]*n)
Once that's available, the rest of the job is trivial.
>>> dict(grouper(range(8), 2))
{0: 1, 2: 3, 4: 5, 6: 7}