Based on Nick D's answer:
>>> from itertools import izip >>> t = [1,2,3,4,5,6,7,8,9,10,11,12] >>> for a, b in izip(*[iter(t)]*2): ... print a, b ... 1 2 3 4 5 6 7 8 9 10 11 12 >>> for a, b, c in izip(*[iter(t)]*3): ... print a, b, c ... 1 2 3 4 5 6 7 8 9 10 11 12 >>> for a, b, c, d in izip(*[iter(t)]*4): ... print a, b, c, d ... 1 2 3 4 5 6 7 8 9 10 11 12 >>> for a, b, c, d, e, f in izip(*[iter(t)]*6): ... print a, b, c, d, e, f ... 1 2 3 4 5 6 7 8 9 10 11 12 >>>
Not readable, but it shows a compact way to get the right tuple size.
source share