Custom zip_longest Implementation with fillvalue

  • Share this:

Code introduction


Create a custom function that uses the zip_longest function from the built-in library itertools to combine multiple iterable objects into an iterator. If an iterable object has fewer elements, it is filled with the fillvalue.


Technology Stack : itertools

Code Type : Custom function

Code Difficulty : Intermediate


                
                    
def zip_longest(*args, fillvalue=0):
    from itertools import zip_longest

    def func(*args, fillvalue=0):
        return zip_longest(*args, fillvalue=fillvalue)

    return func

# JSON representation                
              
Tags: