Combining Iterables with FillValue

  • Share this:

Code introduction


The function is used to combine multiple iterable objects. If the iterable objects have different lengths, it fills in the missing values with fillvalue.


Technology Stack : itertools

Code Type : Function

Code Difficulty : Intermediate


                
                    
def zip_longest(*args, fillvalue=None):
    # This function will return a zip object that aggregates elements from each of the iterables.
    # If the iterables are of uneven length, missing values are filled-in with fillvalue.
    # Uses itertools.zip_longest from the Python standard library.

    import itertools

    return itertools.zip_longest(*args, fillvalue=fillvalue)                
              
Tags: