Combining Iterables with FillValue Using zip_longest

  • Share this:

Code introduction


The function accepts any number of iterable objects as input and combines them into an iterator, with shorter inputs filled at the end with a specified fill value.


Technology Stack : Built-in library zip_longest

Code Type : Function

Code Difficulty : Intermediate


                
                    
def zip_longest(*args, fillvalue=0):
    zip_longest_func = zip_longest(*args, fillvalue=0)
    for i in zip_longest_func:
        print(i)