Combining Iterables with Fillvalue

  • Share this:

Code introduction


The function is used to combine multiple iterable objects into a new iterable object. If the iterable objects have different lengths, fillvalue is used to fill the shorter iterable objects.


Technology Stack : Built-in library

Code Type : Function

Code Difficulty : Intermediate


                
                    
def zip_longest(*args, fillvalue=None):
    zip_longest = zip_longest(*args, fillvalue=fillvalue)
    while True:
        yield zip_longest
        zip_longest = zip_longest(*zip_longest)