Zipping Iterables with Fillvalue

  • Share this:

Code introduction


This function takes multiple input iterables (elements of args) and combines them into a single iterable. If the iterables are of uneven length, missing values in the shorter iterables are filled with fillvalue.


Technology Stack : itertools

Code Type : Iterator processing

Code Difficulty : Intermediate


                
                    
def zip_longest(*args, fillvalue=None):
    """
    Zips the input iterables (elements of args) together into a single iterable.
    If the iterables are of uneven length, missing values in the shorter
    iterables are filled with fillvalue.
    """
    from itertools import zip_longest as zip_longest_imp

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