Wrapper Function for Combining Iterables with Fillvalue

  • Share this:

Code introduction


Create a wrapper function that accepts an arbitrary number of iterable objects as input and returns an iterator that combines these iterables. If any iterable is exhausted, it will be filled with the fillvalue.


Technology Stack : itertools

Code Type : Function

Code Difficulty : Intermediate


                
                    
def zip_longest(*args, fillvalue=None):
    from itertools import zip_longest as it_zip_longest

    def wrapper(*args, fillvalue=None):
        return it_zip_longest(*args, fillvalue=fillvalue)

    return wrapper                
              
Tags: