You can download this code by clicking the button below.
This code is now available for download.
This function is used to concatenate multiple iterable objects. If one iterator is exhausted, it is filled with fillvalue.
Technology Stack : Built-in library
Code Type : Iterator
Code Difficulty : Intermediate
def zip_longest(*args, fillvalue=0):
iters = [iter(arg) for arg in args]
while True:
result = []
for i, it in enumerate(iters):
try:
result.append(next(it))
except StopIteration:
iters[i] = iter([fillvalue])
result.append(fillvalue)
yield tuple(result)