Creating an Extended Zip Function with Fillvalue

  • Share this:

Code introduction


The function creates an iterator that returns tuples, each containing elements from each of the iterable arguments. If one of the iterable arguments runs out of items, it is filled with the fillvalue.


Technology Stack : itertools

Code Type : Function

Code Difficulty : Intermediate


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

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