Customized Zip Function with Fillvalue

  • Share this:

Code introduction


The function is similar to the built-in zip function, but fills the result list with fillvalue if the lengths of the input iterables are uneven.


Technology Stack : itertools

Code Type : Function

Code Difficulty : Intermediate


                
                    
def zip_longest(*args, fillvalue=None):
    """
    Like zip() but the output list is filled with fillvalue if the iterables are of uneven length.
    """
    from itertools import zip_longest as _zip_longest
    return _zip_longest(*args, fillvalue=fillvalue)                
              
Tags: