Zip Longest with Fillvalue

  • Share this:

Code introduction


This function uses `itertools.zip_longest` to merge multiple iterable objects. If one iterable object is shorter than the others, `fillvalue` is used to fill in the gaps.


Technology Stack : itertools

Code Type : Function

Code Difficulty : Intermediate


                
                    
def zip_longest(*args, fillvalue=()):
    from itertools import zip_longest
    return list(zip_longest(*args, fillvalue=fillvalue))

# JSON format output                
              
Tags: