Zip Multiple Iterables with Fillvalue

  • Share this:

Code introduction


This function merges multiple iterable objects (like lists, strings, etc.) into a single iterable. If the iterables are of uneven length, missing values are filled with `fillvalue`.


Technology Stack : itertools

Code Type : Function

Code Difficulty : Intermediate


                
                    
def zip_longest(*args, fillvalue=None):
    """
    Zip the elements of the provided iterables together into a single iterable.
    If the iterables are of uneven length, missing values are filled with `fillvalue`.
    """
    from itertools import zip_longest as _zip_longest

    return _zip_longest(*args, fillvalue=fillvalue)                
              
Tags: