Enhanced Zip Function with Fillvalue

  • Share this:

Code introduction


The function implements similar functionality to the zip function, but fills shorter sequences with fillvalue when the lengths of sequences are different.


Technology Stack : Built-in library - collections

Code Type : Function

Code Difficulty : Intermediate


                
                    
def zip_longest(*args, fillvalue=None):
    zip_longest_func = zip_longest(*args, fillvalue=fillvalue)
    for item in zip_longest_func:
        yield item