Use itertools.izip_longest
, pass the default value to the fillvalue
parameter.
Demo:
In [1]: from itertools import chain, izip_longest
In [2]: a = [1]
In [3]: b = []
In [5]: list(chain(*izip_longest(a, b, fillvalue='foo')))
Out[5]: [1, 'foo']
Default value of fillvalue
is None
.