Iterables Aggregation with Fillvalue

  • Share this:

Code introduction


Create an iterator that aggregates elements from each of the iterables. If the iterables are of uneven length, missing values are filled with fillvalue.


Technology Stack : itertools

Code Type : Function

Code Difficulty : Intermediate


                
                    
def zip_longest(*args, fillvalue=0):
    zip_longest = itertools.zip_longest(*args, fillvalue=fillvalue)
    return [list(pair) for pair in zip_longest]                
              
Tags: