Zip Longest Function with Fillvalue

  • Share this:

Code introduction


This function takes any number of iterable objects and zips them together, filling in missing values with a specified fill value if the iterables are of unequal length.


Technology Stack : itertools

Code Type : Function

Code Difficulty : Intermediate


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

    # This function takes any number of iterables and zips them together, filling in missing values with a specified fillvalue
    return list(zip_longest(*args, fillvalue=fillvalue))                
              
Tags: