To match your own output, you can use izip_longestto fill in with Noneand transpose again to return to the original order
from itertools import izip_longest
tup=( [1,2], [2,3,5], [4,3], [4,5,6,7] )
for a,b,c,d in zip(*izip_longest(*tup)):
print(a,b,c,d)
(1, 2, None, None)
(2, 3, 5, None)
(4, 3, None, None)
(4, 5, 6, 7)
int, float .. , fillvalue izip_longest:
tup=( [1,2], [2,3,5], [4,3], [4,5,6,7])
for a,b,c,d in zip(*izip_longest(*tup,fillvalue=0)):
print(a,b,c,d)
(1, 2, 0, 0)
(2, 3, 5, 0)
(4, 3, 0, 0)
(4, 5, 6, 7)
print, , , python2, , python3, @TimHenigan , , zip_longest.
, itertools.izip, :
from itertools import izip_longest, izip
tup = ( [1, 2], [2, 3, 5], [4, 3], [4, 5, 6, 7])
for a, b, c, d in izip(*izip_longest(*tup, fillvalue=0)):
print(a, b, c, d)